Reset AutoIncrement in SQL Server after Delete

jumbojs picture jumbojs · Feb 4, 2009 · Viewed 378.6k times · Source

I've deleted some records from a table in a SQL Server database. Now the ID's go from 101 to 1200. I want to delete the records again, but I want the ID's to go back to 102. Is there a way to do this in SQL Server?

Answer

Robert Wagner picture Robert Wagner · Feb 4, 2009

Issue the following command to reseed mytable to start at 1:

DBCC CHECKIDENT (mytable, RESEED, 0)

Read about it in the Books on Line (BOL, SQL help). Also be careful that you don't have records higher than the seed you are setting.