Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Server - reset identity field [duplicate]

Tags:

I have a table with a identity column. I need to reset that identity column from zero. What should i do for this.

like image 248
Srinivasan Avatar asked Jan 21 '10 07:01

Srinivasan


People also ask

How can I reset identity column in SQL Server?

Here, to reset the Identity column in SQL Server you can use DBCC CHECKIDENT method. Syntax : DBCC CHECKIDENT ('table_name', RESEED, new_value); Note : If we reset the existing records in the table and insert new records, then it will show an error.

Can identity column have duplicate values?

Duplicate identity values can occur in a table when inserting identity values or reseeding the identity value.

Can identity column have duplicate value in SQL Server?

SQL Server internally manages the values of Identity Columns and does not generate any Duplicate Values.


1 Answers

Use DBCC CHECKIDENT:

DBCC CHECKIDENT(<tablename>, RESEED, 0); 
like image 189
Remus Rusanu Avatar answered Oct 14 '22 20:10

Remus Rusanu