2

I created a table in sqlserver 2012 with a primary key ID with identity turned on, and I found that the values it was inserting went from 1 to 55, then jumped to 1056.

To be clear, the IDs it returned were as follows:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 1056

What causes that to happen?

Jesuraja
  • 3,774
  • 4
  • 24
  • 48
user3785958
  • 71
  • 1
  • 1
  • 4

1 Answers1

0

Generally this is a sign that you accidentally created a bunch of rows then deleted them. I've had this happen through poorly-thought-out loops before, or even just bad application logic. In any event, it's caused by deleting records from the table. It can also be caused by manually altering the identity seed, but unless you're intentionally trying to do that, it's fairly unlikely that it'd happen. Particularly if you work with a team who has access to the database, it's quite conceivable that someone else made some minor mistake that wasted a few values. I'm sure it's nothing worth worrying about.

A quick, inline edit: I see you found reference to a "bug" that does this exact thing. I wasn't aware of that, but it certainly explains it. My points still stand, though. It's really nothing worth worrying about in a majority of cases.

That all said, you can reset the identity column, and a search will certainly tell you how to do that. You could also just drop the column and re-add it. But I normally just ignore it when this sort of thing happens. That thousand won't make any real difference if you're going to hit 2^31 records anyway, and any well-written program won't need the IDs to be in any particular format or under any particular restriction to work.

Matthew Haugen
  • 12,916
  • 5
  • 38
  • 54
  • I didn't delete any rows. but It jump itself to 1056? I don't know. and I have followed this link but still problem . http://www.codeproject.com/Tips/668042/SQL-Server-Auto-Identity-Column-Value-Jump-Is – user3785958 Jul 14 '14 at 10:36
  • Huh, that's very interesting. I wasn't aware of that. I've never seen that happen, but clearly it's possible. Well my point still stands: there's really no cause for alarm unless you *are* intending to show users these values, and I'd advise against that as a general rule anyway if you can avoid it. It's just typically messy. – Matthew Haugen Jul 14 '14 at 10:38