SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Autonumber field sometimes skips a 1000


Autonumber field sometimes skips a 1000

Author
Message
haastnooit
haastnooit
Valued Member
Valued Member (65 reputation)Valued Member (65 reputation)Valued Member (65 reputation)Valued Member (65 reputation)Valued Member (65 reputation)Valued Member (65 reputation)Valued Member (65 reputation)Valued Member (65 reputation)

Group: General Forum Members
Points: 65 Visits: 20
I have an order table with an ID field as its primary key. This is a straightforward indentity field which increment with each new record, well that's how its supposed to work anyway.
Every now and then it skips a 1000 numbers for no apparent reason, see example below:
108373
108369
107360
107357

And:

107336
107335
106340
106338

These are actual committed orders, so its normal that it sometime skips a couple of numbers. But a thousand is a bit strange. H

Has anybody every encountered this issue and what can I do about it?
GilaMonster
GilaMonster
SSC Guru
SSC Guru (222K reputation)SSC Guru (222K reputation)SSC Guru (222K reputation)SSC Guru (222K reputation)SSC Guru (222K reputation)SSC Guru (222K reputation)SSC Guru (222K reputation)SSC Guru (222K reputation)

Group: General Forum Members
Points: 222361 Visits: 46288
SQL Server 2012?

Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass


Erland Sommarskog
Erland Sommarskog
SSCertifiable
SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)

Group: General Forum Members
Points: 5156 Visits: 875
This is more likely to happen in SQL 2012 where they have changed caching for IDENTITY, so numbers may skip more abruptly when SQL Server is restarted. But there are lots of other possible reasons. For instance, someone runs a mass-insert of 1000 rows which fails or is rolled back.

What you should do about it? Nothing, of course. When you chose to use IDENTITY, you also chose to accept gaps, and whether these gaps are 1, 2,3 or 1000 is immaterial.

Erland Sommarskog, SQL Server MVP, www.sommarskog.se
haastnooit
haastnooit
Valued Member
Valued Member (65 reputation)Valued Member (65 reputation)Valued Member (65 reputation)Valued Member (65 reputation)Valued Member (65 reputation)Valued Member (65 reputation)Valued Member (65 reputation)Valued Member (65 reputation)

Group: General Forum Members
Points: 65 Visits: 20
Thanks for your replies, very much appreciated.

I know for sure the mass inserts are not happening, but the restart of the service sounds like a possible cause.
Normally i would not have a problem with it, but the thing is that the cilent sees these gaps as well, so i need to reassure him there is no problem.
So you are sure there is no reason for alarm?

If they happen more than often i should probably find the cause of the restarts of the service?
GilaMonster
GilaMonster
SSC Guru
SSC Guru (222K reputation)SSC Guru (222K reputation)SSC Guru (222K reputation)SSC Guru (222K reputation)SSC Guru (222K reputation)SSC Guru (222K reputation)SSC Guru (222K reputation)SSC Guru (222K reputation)

Group: General Forum Members
Points: 222361 Visits: 46288
Identity is not and never has been guaranteed to be without gaps. Hence the presence of such gaps it to be expected.

If the service is restarting, you probably want to find out why. Check your error logs to see if it is.

Again, is this SQL Server 2012?

Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass


psingla
psingla
Ten Centuries
Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)

Group: General Forum Members
Points: 1398 Visits: 1249
does it always skips 1000 rows or any random number?

Pramod
SQL Server DBA | MCSE SQL Server 2012/2014

in.linkedin.com/in/pramodsingla/
http://pramodsingla.wordpress.com/
Erland Sommarskog
Erland Sommarskog
SSCertifiable
SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)

Group: General Forum Members
Points: 5156 Visits: 875
IDENTITY can give you gaps, and if gaps are a concern, you should not use IDENTITY. You use IDENTITY (or sequences in SQL 2012) to improve concurrency. Because IDENTITY is not transactional, there is no serialisation.

Explain to the customers, that these numbers are completely arbitrary and that gaps of all sorts can be expected. And you should not waste your time on finding out why these gaps occur, because you already have the answer: you use IDENTITY and asked for it to happen.

Erland Sommarskog, SQL Server MVP, www.sommarskog.se
Sean Pearce
Sean Pearce
SSCarpal Tunnel
SSCarpal Tunnel (4K reputation)SSCarpal Tunnel (4K reputation)SSCarpal Tunnel (4K reputation)SSCarpal Tunnel (4K reputation)SSCarpal Tunnel (4K reputation)SSCarpal Tunnel (4K reputation)SSCarpal Tunnel (4K reputation)SSCarpal Tunnel (4K reputation)

Group: General Forum Members
Points: 4024 Visits: 3436
psingla (7/5/2013)
does it always skips 1000 rows or any random number?

SQL Server 2012 uses blocks of 1000 in a cache. When you restart the SQL Server service the next block of 1000 is used.



The SQL Guy @ blogspot

@SeanPearceSQL

About Me
haastnooit
haastnooit
Valued Member
Valued Member (65 reputation)Valued Member (65 reputation)Valued Member (65 reputation)Valued Member (65 reputation)Valued Member (65 reputation)Valued Member (65 reputation)Valued Member (65 reputation)Valued Member (65 reputation)

Group: General Forum Members
Points: 65 Visits: 20
Its actuallySQl Server 2008.

I cant find anything in the logfiles about a restart of the service.
Erland Sommarskog
Erland Sommarskog
SSCertifiable
SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)

Group: General Forum Members
Points: 5156 Visits: 875
So maybe there is a failed mass-insert after all. Anyway, again, this is nothing you should waste your time on. Seriously.

Erland Sommarskog, SQL Server MVP, www.sommarskog.se
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search