Tuesday

Code - Reset Auto Increment in SQL Server after Deleting Records

So during development its very common that developers create enormous amount of test record into the table and once you delete all those test records or even clean the whole table the next record you are going to enter its auto incrementable id will not start from 0 rather it will start from what was the id of the last record you had created.

To over-come this problem you can simply issue the following command to reseed TestTable to start at 1:


DBCC CHECKIDENT (TestTable, RESEED, 0)


Just be careful while setting the seed value and make sure that you don't have any record with the ID higher than the seed value, which is 0 in our case here.

No comments:

Post a Comment

Your comments are highly appreciated!