-1

I have created an application, what is connected to MS SQL 2012 databases. We have more then 60 clients in the local area. It works well, but today I have found a little issue. When I have checked the datas, I have found missing IDs.

Loaded datas

The ID is not depends on the app, it is SQL setting. When somebody save new data (I am using "INSERT" command), then the sql table increment the ID by 1. But here are missing the 19571 and 19572.

I am just wondering, how it is possible.

SQL Table Desingner

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
ahollod
  • 3
  • 1

2 Answers2

0

It would be possible through any insertion which was in a transaction which rolled back, the number would of been allocated and used by the transaction, but on rollback, you would find it missing.

Normally with identity fields you should not be worried about gaps in the IDs, they should be considered arbitrary unique identifiers.

Andrew
  • 26,629
  • 5
  • 63
  • 86
0

Presumably, you are referring to an identity column. Basically, SQL Server does not guarantee gapless numbers. The only guarantee is that these are increasing -- and unique if the column is declared unique or a primary key.

There are two primary reasons why this occurs.

  1. Failed updates can "use up" numbers that are no repaced.
  2. Optimization can allocate a group of numbers, causing caps for inserts on other sequences.

This is actually explained in the documentation. In particular, the following are not guaranteed

  • Uniqueness of the value
  • Consecutive values within a transaction
  • Consecutive values after server restart or other failure. – SQL Server might cache identity values for performance reasons.
  • Reuse of values.
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786