Wednesday 5 February 2014

How To Reset Identity column in SQL Server

DBCC CHECKIDENT can reseed (reset) the identity value of the table. For example, if Table has 25 rows with 25 as last identity. If we want next record to have identity as 40 we need to run following T SQL script in Query Analyzer.
DBCC CHECKIDENT (yourtablereseed39)
If table has to start with an identity of 1 with the next insert then table should be reseeded with the identity to 0. And we have to run the following TSQL script in Query Analyzer.
DBCC CHECKIDENT (yourtablereseed39)
If identity seed is set below values that currently are in table, it will violate the uniqueness constraint as soon as the values start to duplicate and will generate error.

No comments:

Post a Comment