Reset Identity column to zero in SQL Server?

Mohammad Dayyan picture Mohammad Dayyan · Dec 19, 2010 · Viewed 22.7k times · Source

How can I reset the Identity column of a table to zero in SQL Server?

Edit:

How can we do it with LINQ to SQL ?

Answer

Randy Minder picture Randy Minder · Dec 19, 2010
DBCC CHECKIDENT (MyTable, RESEED, NewValue)

You can also do a Truncate Table, but, of course, that will remove all rows from the table as well.

To do this via L2S:

db.ExecuteCommand("DBCC CHECKIDENT('MyTable', RESEED, NewValue);");

Or, you can call a stored procedure, from L2S, to do it