SQL Server 2014 – Massive Identity Column Value Jump

identitysql serversql server 2014

So in the middle of basic coding and testing we saw a huge non-patterned jump in Identity values for multiple tables. We are unaware of any server blips or attempted bulk operations, but DBAs are looking into logs.

The gaps are not the typical 1,000 or 10,000 seen with server restarts and such.

The gap for Application_NO is 10,410,345 for a table with 2,320 rows

Transaction_Payment_NO jumped an astonishing 1,712,149,313 for a table with 685 records.

Any ideas on what could be causing such large and seemingly arbitrary jumps?

Identity value jumps on multiple tables

Best Answer

Some possible culprits:

  1. the testing process creates many rows in a transaction, and then rolls back the transaction

This seems like the most likely reason, as you mentioned you're currently doing testing. Perhaps there are some automated tests being run that make changes to those tables, verify the results, and then roll back the changes.

Identity values are not reused after a transaction has been rolled back, which is what causes you to see large gaps in this scenario.

  1. Someone used the RESEED command

You can manually change the current "next identity" value with this command:

DBCC CHECKIDENT ('dbo.Transaction_Payment_NO', RESEED, 1712149313);

This one seems less likely, because you or one of the admins would have to go out of their way to do it. Similarly...

  1. Someone inserted those values manually

You can insert whatever you like into an IDENTITY column by first running this statement:

SET IDENTITY_INSERT dbo.Transaction_Payment_NO ON;
  1. Failovers and restarts

You mentioned this in the question, but just for completeness - SQL Server caches identity values in order to improve performance. But those pre-allocated identity values can be lost if the service restarts or an AG failover occurs. This leads to more predictable gaps though (10,000 on modern versions of SQL Server).