DBCC CHECKIDENT is used to reset the identity column of a table in SQL Server database. e.g. If a table "TEST" has Identity column and currently has 10 records. The next Identity column value would be (say ) "11", but we want the Identity column to be (say) 21, for that we need to reset the Identity column value. The Syntax to perform this task in SQL Server is as :
DBCC CHECKIDENT(,RESEED, Value)
so the sql code to reset would be DBCC CHECKINDENT(TEST, RESEED, 20)
This will make the next row identity column value as 21.
NOTE: If the Identity column is set below the current value in the table it will violate the unique value constraint and will display an error message. And in order to perform this sql command admin rights are required in SQL Server.
No comments:
Post a Comment