DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Reset Identity Column Value Of Table

12.15.2011
| 1980 views |
  • submit to reddit
        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.

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.

<a href="http://www.java-forums.org/blogs/spring-framework/"><strong>Spring Framework</strong></a>