July 4, 2013 at 8:06 am
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?
July 4, 2013 at 8:09 am
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
July 4, 2013 at 4:08 pm
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.
[font="Times New Roman"]Erland Sommarskog, SQL Server MVP, www.sommarskog.se[/font]
July 5, 2013 at 12:43 am
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?
July 5, 2013 at 1:13 am
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
July 5, 2013 at 1:29 am
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/
July 5, 2013 at 2:04 am
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.
[font="Times New Roman"]Erland Sommarskog, SQL Server MVP, www.sommarskog.se[/font]
July 5, 2013 at 7:28 am
July 5, 2013 at 8:01 am
Its actuallySQl Server 2008.
I cant find anything in the logfiles about a restart of the service.
July 5, 2013 at 1:16 pm
So maybe there is a failed mass-insert after all. Anyway, again, this is nothing you should waste your time on. Seriously.
[font="Times New Roman"]Erland Sommarskog, SQL Server MVP, www.sommarskog.se[/font]
Viewing 10 posts - 1 through 9 (of 9 total)
You must be logged in to reply to this topic. Login to reply