Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Autonumber field sometimes skips a 1000 Expand / Collapse
Author
Message
Posted Thursday, July 4, 2013 8:06 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Friday, July 5, 2013 7:52 AM
Points: 7, Visits: 19
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?
Post #1470446
Posted Thursday, July 4, 2013 8:09 AM


SSC-Forever

SSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-Forever

Group: General Forum Members
Last Login: Today @ 12:24 PM
Points: 42,774, Visits: 35,872
SQL Server 2012?


Gail Shaw
Microsoft Certified Master: SQL Server 2008, MVP
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

Post #1470447
Posted Thursday, July 4, 2013 4:08 PM


SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: 2 days ago @ 3:04 PM
Points: 801, Visits: 715
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
Post #1470524
Posted Friday, July 5, 2013 12:43 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Friday, July 5, 2013 7:52 AM
Points: 7, Visits: 19
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?
Post #1470588
Posted Friday, July 5, 2013 1:13 AM


SSC-Forever

SSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-Forever

Group: General Forum Members
Last Login: Today @ 12:24 PM
Points: 42,774, Visits: 35,872
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 2008, MVP
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

Post #1470600
Posted Friday, July 5, 2013 1:29 AM


SSChasing Mays

SSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing Mays

Group: General Forum Members
Last Login: Wednesday, August 20, 2014 11:52 PM
Points: 608, Visits: 1,028
does it always skips 1000 rows or any random number?

Pramod
SQL Server DBA | MCSA SQL Server 2012

in.linkedin.com/in/pramodsingla/
http://pramodsingla.wordpress.com/
Post #1470607
Posted Friday, July 5, 2013 2:04 AM


SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: 2 days ago @ 3:04 PM
Points: 801, Visits: 715
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
Post #1470621
Posted Friday, July 5, 2013 7:28 AM


SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Yesterday @ 7:47 AM
Points: 872, Visits: 2,784
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
Post #1470731
Posted Friday, July 5, 2013 8:01 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Friday, July 5, 2013 7:52 AM
Points: 7, Visits: 19
Its actuallySQl Server 2008.

I cant find anything in the logfiles about a restart of the service.
Post #1470746
Posted Friday, July 5, 2013 1:16 PM


SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: 2 days ago @ 3:04 PM
Points: 801, Visits: 715
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
Post #1470855
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse