How to avoid holes in autoincremental Integer Primary Key ID’s
Apr 19th, 2009 by ocvirek.com
You did some testing on your database before deploying it and you created new record and then deleted it right away, but there is a hole in your primary key ID’s now and it shouldn’t be. How to fix that before deploying it to production environment ?
It’s quite easy, just open SQL Server Managment Studio and fix it using this T-SQL:
DECLARE @LastID int
SELECT @LastID = MAX(ID) FROM MyTable
DBCC CHECKIDENT (’MyTable‘, RESEED, @LastID)