SQL Server continue identity count after truncating table

ckpepper02 picture ckpepper02 · Jul 1, 2013 · Viewed 10.4k times · Source

I seem to remember in MySQL when truncating a table the auto incremented index field would continue where it left off. So if said table was truncated with the highest id was 100, the next id after truncation would be 101.

Is there a way to do this in SQL Server? I truncated my table with over 1000 rows, but after truncating the next new id went back to 1 in my identity column. I would like for it to continue.

Answer

GrandMasterFlush picture GrandMasterFlush · Jul 1, 2013

DBCC CHECKIDENT (<table name>, reseed, 1000) should do the trick.

Note that the the reseed shown above will mean that the next number will be 1001, so set to 999 if you want the next ID to be 1000.

This article explains a bit more.