Ok, I am a bit less experienced in database topics, but consider the situation where you have a field named id in your table, and it’s Indexable/Increment-seeding.
So maybe you have rows 1-60 , so id is between 1-60, and the increment is at “61”.
Well if you delete rows 30-50, shouldn’t the increment go back down to “31”? Filling in those 30-50 ids, and then going back to 61?
My Question::: Why doesn’t MSSQL / SQL Server, do this? The missing unused ids between 30-50, are never to be used again.
Further, what if you manually inserted some rows, between id 500-600? When the increment gets to “500”, will it not give a “duplicate key” error? ???
So if you have some sort of table that is constantly changed by every user—deleting, inserting, deleting, inserting, you better hope id is bigint, because it’s going to quickly go into the 1,000,000+ area if you have enough users.
If you are using autoincrement fields, it is highly recommended to just let SQL Server handle the values for you. It does so in such a way as to minimize integrity conflicts.
That said, if you really want to reset the id values after a large delete, consider using
TRUNCATE TABLE(which will reset the autoincrement value automatically) if you are purging the entire table, orDBCC CHECKIDENTif you need finer control over how this works.EDIT:
This is to demonstrate the behavior of SQL Server when there is a manually-perpetrated gap in autoincrement ID values: