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


Regarding sql server 2012 identity number gap problem after restarting sql server 2012


Regarding sql server 2012 identity number gap problem after restarting sql server 2012

Author
Message
pksutha
pksutha
Valued Member
Valued Member (51 reputation)Valued Member (51 reputation)Valued Member (51 reputation)Valued Member (51 reputation)Valued Member (51 reputation)Valued Member (51 reputation)Valued Member (51 reputation)Valued Member (51 reputation)

Group: General Forum Members
Points: 51 Visits: 58
Hi friends,

I've a problem in sql server 2012, like i've one table, table name is "tblA".
In that Identity field Name is ID bigint not null identity[1,1].
Now i'm making few records entry like from 1 to 5.
Then i've close the sql server 2012. Then i've restarting the system.
Again i'm making another record entry. Here it should come ID value is 6.
But it has come like
10001.
Then again u make entry its coming correct 10002, 10003,10004 etc...
But i need when u restart the system it should continue with existing example
ID value 5+1=6, should start from 6 but its coming 10001...
Plz help why its coming like this.
Koen Verbeeck
Koen Verbeeck
One Orange Chip
One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)

Group: General Forum Members
Points: 27715 Visits: 13268
pksutha (7/22/2013)
Hi friends,

I've a problem in sql server 2012, like i've one table, table name is "tblA".
In that Identity field Name is ID bigint not null identity[1,1].
Now i'm making few records entry like from 1 to 5.
Then i've close the sql server 2012. Then i've restarting the system.
Again i'm making another record entry. Here it should come ID value is 6.
But it has come like
10001.
Then again u make entry its coming correct 10002, 10003,10004 etc...
But i need when u restart the system it should continue with existing example
ID value 5+1=6, should start from 6 but its coming 10001...
Plz help why its coming like this.


The IDENTITY property doesn't give any garantuee there will be no gaps.
SQL Server 2012 caches some of the next identities that might be inserted, in order to speed up the performance. If you restart the server, this cache will be lost.

Maybe you can try to take a look at sequences, if avoiding gaps is important.


How to post forum questions.
Need an answer? No, you need a question.
What’s the deal with Excel & SSIS?
My blog at SQLKover.

MCSE Business Intelligence - Microsoft Data Platform MVP
GilaMonster
GilaMonster
SSC Guru
SSC Guru (88K reputation)SSC Guru (88K reputation)SSC Guru (88K reputation)SSC Guru (88K reputation)SSC Guru (88K reputation)SSC Guru (88K reputation)SSC Guru (88K reputation)SSC Guru (88K reputation)

Group: General Forum Members
Points: 88743 Visits: 45284
Koen Verbeeck (7/23/2013)
Maybe you can try to take a look at sequences, if avoiding gaps is important.


Sequences have the same gap-causing properties as identities (identities in SQL 2012 use the Sequence code)

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


Grant Fritchey
Grant Fritchey
SSC-Forever
SSC-Forever (40K reputation)SSC-Forever (40K reputation)SSC-Forever (40K reputation)SSC-Forever (40K reputation)SSC-Forever (40K reputation)SSC-Forever (40K reputation)SSC-Forever (40K reputation)SSC-Forever (40K reputation)

Group: General Forum Members
Points: 40773 Visits: 32666
This is a known behavior. I reported it as a bug a while back. Microsoft has supplied a work around. You can enable TraceFlag 272 on your server. There are other workarounds as well. Check out the Connect entry for more information.

----------------------------------------------------
The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood...
Theodore Roosevelt

The Scary DBA
Author of: SQL Server Query Performance Tuning and SQL Server Execution Plans
Product Evangelist for Red Gate Software
Erland Sommarskog
Erland Sommarskog
SSCrazy
SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)

Group: General Forum Members
Points: 2135 Visits: 872
pksutha (7/22/2013)
Again i'm making another record entry. Here it should come ID value is 6.


No. It should become a value > 5.

If you need consecutive numbers, you should not use IDENTITY. The point with IDENTITY and sequences is that they are non-blocking. That is, one process can get a number although another process that just took a number has not yet committed. This also means that there can be gaps if there is a rollback. And in some cases there can be bigger gaps. Which is perfectly OK, and it is completely beyond me why Microsoft wasted time on this trace flag.

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