IDENT_CURRENT()

  • Comments posted to this topic are about the item IDENT_CURRENT()

  • Good back to basics question thanks Steve.

    ...

  • Nice one, thanks Steve.
    However, it appears option 2 & 3 are exactly the same.

    ____________________________________________
    Space, the final frontier? not any more...
    All limits henceforth are self-imposed.
    “libera tute vulgaris ex”

  • Stewart "Arturius" Campbell - Thursday, December 21, 2017 3:50 AM

    Nice one, thanks Steve.
    However, it appears option 2 & 3 are exactly the same.

    My bad - missed the "My" in the3rd option (quickly wiping egg off face).....

    ____________________________________________
    Space, the final frontier? not any more...
    All limits henceforth are self-imposed.
    “libera tute vulgaris ex”

  • This must be a MS Question 🙂  One of those splitting hairs (in my opinion)
    The difference between Highest value and Last value - REALLY  ?
    Thanks for making be think 🙂

  • Thanks for the instructive question.

    - webrunner

    -------------------
    A SQL query walks into a bar and sees two tables. He walks up to them and asks, "Can I join you?"
    Ref.: http://tkyte.blogspot.com/2009/02/sql-joke.html

  • Budd - Thursday, December 21, 2017 6:52 AM

    This must be a MS Question 🙂  One of those splitting hairs (in my opinion)
    The difference between Highest value and Last value - REALLY  ?
    Thanks for making be think 🙂

    Not really the same thing considering the identity column can be reseeded to values less than the initial value when the column was created.


    CREATE TABLE [dbo].[testident] (
      testidentId INT IDENTITY(1,1)
      , testvalue INT
    );

    INSERT INTO [dbo].[testident]([testvalue])
    VALUES (1),(2),(10),(25);

    SELECT * FROM [dbo].[testident] AS [t];
    SELECT IDENT_CURRENT('dbo.testident');

    DBCC CHECKIDENT([testident], RESEED, -10);


    INSERT INTO [dbo].[testident]([testvalue])
    VALUES (100),(200),(1000),(2500);

    SELECT * FROM [dbo].[testident] AS [t];
    SELECT IDENT_CURRENT('dbo.testident');

  • Lynn Pettis - Thursday, December 21, 2017 11:27 AM

    Budd - Thursday, December 21, 2017 6:52 AM

    This must be a MS Question 🙂  One of those splitting hairs (in my opinion)
    The difference between Highest value and Last value - REALLY  ?
    Thanks for making be think 🙂

    Not really the same thing considering the identity column can be reseeded to values less than the initial value when the column was created.


    CREATE TABLE [dbo].[testident] (
      testidentId INT IDENTITY(1,1)
      , testvalue INT
    );

    INSERT INTO [dbo].[testident]([testvalue])
    VALUES (1),(2),(10),(25);

    SELECT * FROM [dbo].[testident] AS [t];
    SELECT IDENT_CURRENT('dbo.testident');

    DBCC CHECKIDENT([testident], RESEED, -10);


    INSERT INTO [dbo].[testident]([testvalue])
    VALUES (100),(200),(1000),(2500);

    SELECT * FROM [dbo].[testident] AS [t];
    SELECT IDENT_CURRENT('dbo.testident');

    TRUE that is a possibility.
    and maybe it would happen,  perhaps in bizarreO world 🙂
    I've never seen the need and fail to understand - WHY would something like that be needed.
    But, I get it, it can happen.

  • Budd - Thursday, December 21, 2017 11:46 AM

    Lynn Pettis - Thursday, December 21, 2017 11:27 AM

    Budd - Thursday, December 21, 2017 6:52 AM

    This must be a MS Question 🙂  One of those splitting hairs (in my opinion)
    The difference between Highest value and Last value - REALLY  ?
    Thanks for making be think 🙂

    Not really the same thing considering the identity column can be reseeded to values less than the initial value when the column was created.


    CREATE TABLE [dbo].[testident] (
      testidentId INT IDENTITY(1,1)
      , testvalue INT
    );

    INSERT INTO [dbo].[testident]([testvalue])
    VALUES (1),(2),(10),(25);

    SELECT * FROM [dbo].[testident] AS [t];
    SELECT IDENT_CURRENT('dbo.testident');

    DBCC CHECKIDENT([testident], RESEED, -10);


    INSERT INTO [dbo].[testident]([testvalue])
    VALUES (100),(200),(1000),(2500);

    SELECT * FROM [dbo].[testident] AS [t];
    SELECT IDENT_CURRENT('dbo.testident');

    TRUE that is a possibility.
    and maybe it would happen,  perhaps in bizarreO world 🙂
    I've never seen the need and fail to understand - WHY would something like that be needed.
    But, I get it, it can happen.

    Not necessarily in bizarreO world.  I have read numerous threads asking about reseeding identity columns, so it happens more frequently than you may realize.  Do I agree with doing it?  That would depend on why it was being done.

  • Lynn Pettis - Thursday, December 21, 2017 12:27 PM

    Budd - Thursday, December 21, 2017 11:46 AM

    Lynn Pettis - Thursday, December 21, 2017 11:27 AM

    Budd - Thursday, December 21, 2017 6:52 AM

    This must be a MS Question 🙂  One of those splitting hairs (in my opinion)
    The difference between Highest value and Last value - REALLY  ?
    Thanks for making be think 🙂

    Not really the same thing considering the identity column can be reseeded to values less than the initial value when the column was created.


    CREATE TABLE [dbo].[testident] (
      testidentId INT IDENTITY(1,1)
      , testvalue INT
    );

    INSERT INTO [dbo].[testident]([testvalue])
    VALUES (1),(2),(10),(25);

    SELECT * FROM [dbo].[testident] AS [t];
    SELECT IDENT_CURRENT('dbo.testident');

    DBCC CHECKIDENT([testident], RESEED, -10);


    INSERT INTO [dbo].[testident]([testvalue])
    VALUES (100),(200),(1000),(2500);

    SELECT * FROM [dbo].[testident] AS [t];
    SELECT IDENT_CURRENT('dbo.testident');

    TRUE that is a possibility.
    and maybe it would happen,  perhaps in bizarreO world 🙂
    I've never seen the need and fail to understand - WHY would something like that be needed.
    But, I get it, it can happen.

    Not necessarily in bizarreO world.  I have read numerous threads asking about reseeding identity columns, so it happens more frequently than you may realize.  Do I agree with doing it?  That would depend on why it was being done.

    Another scenario where IDENT_CURRENT does not equal the highest value - - If you roll back an insert, the identity value(s) that would have been used in the transaction are skipped over. My $0.02

  • WILLIAM MITCHELL - Thursday, December 21, 2017 2:57 PM

    Lynn Pettis - Thursday, December 21, 2017 12:27 PM

    Budd - Thursday, December 21, 2017 11:46 AM

    Lynn Pettis - Thursday, December 21, 2017 11:27 AM

    Budd - Thursday, December 21, 2017 6:52 AM

    This must be a MS Question 🙂  One of those splitting hairs (in my opinion)
    The difference between Highest value and Last value - REALLY  ?
    Thanks for making be think 🙂

    Not really the same thing considering the identity column can be reseeded to values less than the initial value when the column was created.


    CREATE TABLE [dbo].[testident] (
      testidentId INT IDENTITY(1,1)
      , testvalue INT
    );

    INSERT INTO [dbo].[testident]([testvalue])
    VALUES (1),(2),(10),(25);

    SELECT * FROM [dbo].[testident] AS [t];
    SELECT IDENT_CURRENT('dbo.testident');

    DBCC CHECKIDENT([testident], RESEED, -10);


    INSERT INTO [dbo].[testident]([testvalue])
    VALUES (100),(200),(1000),(2500);

    SELECT * FROM [dbo].[testident] AS [t];
    SELECT IDENT_CURRENT('dbo.testident');

    TRUE that is a possibility.
    and maybe it would happen,  perhaps in bizarreO world 🙂
    I've never seen the need and fail to understand - WHY would something like that be needed.
    But, I get it, it can happen.

    Not necessarily in bizarreO world.  I have read numerous threads asking about reseeding identity columns, so it happens more frequently than you may realize.  Do I agree with doing it?  That would depend on why it was being done.

    Another scenario where IDENT_CURRENT does not equal the highest value - - If you roll back an insert, the identity value(s) that would have been used in the transaction are skipped over. My $0.02

    And that is a more likely scenario.

  • nice question to learn new things....😎😎😎😎

    Manik
    You cannot get to the top by sitting on your bottom.

  • WILLIAM MITCHELL - Thursday, December 21, 2017 2:57 PM

    Another scenario where IDENT_CURRENT does not equal the highest value - - If you roll back an insert, the identity value(s) that would have been used in the transaction are skipped over. My $0.02

    Yet another scenario is where a row is simply deleted.

    An possible but unlikely scenario is that the row is transferred from current data to historical data, so that it's no longer in the current table - I don't really see this happening with the most recently assigned identity, but it is probably possible in the scrambled mess that is a typical database designed by non-data people.

    Tom

  • TomThomson - Tuesday, January 2, 2018 8:48 AM

    WILLIAM MITCHELL - Thursday, December 21, 2017 2:57 PM

    Another scenario where IDENT_CURRENT does not equal the highest value - - If you roll back an insert, the identity value(s) that would have been used in the transaction are skipped over. My $0.02

    Yet another scenario is where a row is simply deleted.

    An possible but unlikely scenario is that the row is transferred from current data to historical data, so that it's no longer in the current table - I don't really see this happening with the most recently assigned identity, but it is probably possible in the scrambled mess that is a typical database designed by non-data people.

    This i can relate to - we recently "inherited" such a database from an analyst that resigned - no-one even knew about this till now....

    ____________________________________________
    Space, the final frontier? not any more...
    All limits henceforth are self-imposed.
    “libera tute vulgaris ex”

Viewing 14 posts - 1 through 13 (of 13 total)

You must be logged in to reply to this topic. Login to reply