question

programmablephysics avatar image
programmablephysics asked

ID is primary key value increasing by +15 or +random number every time I add a row

HELP! In SQL Server, I do not know reason why primary Key UrunID value increased from 14 to 29 from one row to the one below. It's value increased by 15.

The rows increases like this,
first row : 14

second row : 29

3rd row : 30

4th row : 32

Seems random. Help!

1672427900765.png

tablesqlservertablesprimary-key
1672427900765.png (12.1 KiB)
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Jeff Moden avatar image
Jeff Moden answered

First, check the SEED and INCREMENT values for the column by changing the table name in the following code and running it.

 SELECT  ColName = idcol.name
        ,idcol.seed_value
        ,idcol.increment_value
        ,idcol.last_value
   FROM sys.identity_columns idcol
  WHERE object_id = OBJECT_ID('PutYour2PartTableNameHere')
;

If that looks ok, then it's not the fault of the IDENTITY property on the column. Most likely, someone is doing row deletes. You could put a trigger on the table to see who or what is doing the deletes.


10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.