Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Languages / SQL

Reset Table Identity

4.95/5 (20 votes)
13 Nov 2010CPOL 37.8K  
SQL SERVER – DBCC RESEED Table Identity Value – Reset Table Identity
DBCC CHECKIDENT can reset the identity value of the table.
For example, Your Table has 25 rows with 25 as last identity. If we want next record to have identity as 35, we need to run the following TSQL script in Query Analyzer.

SQL
DBCC CHECKIDENT (yourtable, reseed, 34)


If table has to start with an identity of 1 with the next insert, then table should be reseeded with the identity to 0.

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.

Please do let me know if you have any doubt.

Please provide "Vote":thumbsup: if this would be helpful.:rose:

Thanks,
Imdadhusen

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)