Sunday, December 5, 2010

Reset Identity Column

Resetting the next insert value in SQL Server can be done using DBCC CHECKIDENT.

Here's the syntax from MSDN.
 
DBCC CHECKIDENT 
 ( 
    table_name
        [, { NORESEED | { RESEED [, new_reseed_value ] } } ]
)
[ WITH NO_INFOMSGS ]

Here's how to check the next value.

 DBCC CHECKIDENT ("table_name", NORESEED)

Here's how to reset the value.

DBCC CHECKIDENT("table_name", RESEED, 0)
(*NOTE: The value of the next insert will be 1)


NOTES:
http://msdn.microsoft.com/en-us/library/ms176057.aspx

No comments:

Post a Comment