How to reset initial increment id value in SQL Server

I would like to have a nice template for this in development. How to reset initial value of increment identifier in SQL Server?

+45
sql-server identity
Aug 19 '08 at 21:14
source share
3 answers
DBCC CHECKIDENT('TableName', RESEED, 0) 
+82
Aug 19 '08 at 21:18
source share
— -

Just a warning word with:

 DBCC CHECKIDENT (MyTable, RESEED, 0) 

If you did not truncate the table, and the identification column is a PC, you will receive an error message when reaching previously existing identifiers.

For example, you already have identifiers (3,4,5) in the table. Then you specify the reset column with identifier 1. After entering identifier 2, the next insert will try to use identifier 3, which will not be executed.

+26
Aug 19 '08 at 21:40
source share

To establish identity 100:

 DBCC CHECKIDENT (MyTable, RESEED, 100) 
+10
Aug 19 '08 at 21:21
source share



All Articles