I have a table with a identity primary key column. Its last value is 5228491220 using IDENT_CURRENT.
I make a full backup of the database, restore it on a second server. (We backup and restore daily from one server to the other one.) Immediately I pull IDENT_CURRENT from this table and the value is 5228501279.
That is, the restore jumps the last value by more than 10000.
I can't make sense of it. Why would the last value of this identity column not be carried properly through the backup?
More practically, how do I make sure the value carries over properly?
Best Answer
If you're on SQL Server 2012 (or newer), you may be running into a planned change, where identity values are retrieved in batches, and the next ID value may be incremented after a shutdown, or a restore.
Quick summary: SQL grabs its IDENTITY values in batches, and if it's not sure what the last ID used was, it will increment the next IDENTITY value by 10 (for
tinyint
) to 10000 (forbigint
) when starting back up.(Compiled from comments)