Where does the last identity value would be stored

  • I have an identity column in a table with an incremental seed of 1 and starting with 1

    I have inserted 5 rows where the last identity value would be 5

    suppose i delete the 5th row and when i insert another row the identity column value would contain 6.

    so where exactly sql server saves the last identity value of a table.

  • to check the last\current id column value used execute the following query

    dbcc checkident('tablename', noreseed)

    -----------------------------------------------------------------------------------------------------------

    "Ya can't make an omelette without breaking just a few eggs" 😉

  • vamshi.kotagiri (11/13/2010)


    I have an identity column in a table with an incremental seed of 1 and starting with 1

    I have inserted 5 rows where the last identity value would be 5

    suppose i delete the 5th row and when i insert another row the identity column value would contain 6.

    so where exactly sql server saves the last identity value of a table.

    It's stored internally, not in a table you can update directly (or even see).

    The only way to change it is via the DBCC CHECKIDENT utility.

    If you just want to see what the last value used was, and other information about the column with the identity property, query the system view sys.identity_columns.

  • SELECT IDENT_CURRENT('my_table')

Viewing 4 posts - 1 through 3 (of 3 total)

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