Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Identity Increment Jumping

Status
Not open for further replies.

dvannoy

MIS
May 4, 2001
2,765
US
I have a primary key set as int, Is Identity = YES, Identity Increment = 1

I have noticed that the increment went from 49 to 1042 Why ?? Running SQL Server 2012

I have googled and found others having this issue. How do you stop this from happening ?

Any help would be appreciated

Thanks
 
If you googled, you should also have found the reason behind it.
This happens with restarts. SQL Server rather prevents double values than gaps. It's no bug, it's by design.
Does it matter? Typically the values are used for unique keys and you get unique keys.

If it really matters to you, you can use sequences or trace flag 272.
Shedding more light on this:
Bye, Olaf.
 
I have one table that I'm returning the Key field back to the user as the document number. I would like those numbers to stay in a sequence if possible and not jump at random.
 
Yes I did, thank you. I tried adding the flag 272 to the sql startup but the number still jumped after a restart. I don't need to use the primary key I'm just trying to create some sort of number sequence to give back to the user once the transaction is complete. I just would like those transaction number to stay as close together in sequence as possible.
 
Well, saying this happens "at random" after having read the explanations to me points out you didn't read. You normally won't have crashes and if you shutdown you can do gracefully as Kalen Delaney explains.
You did something wrong if this trace flag didn't help. -t272

As you are on SQL2012, you can also switch to using a sequence:
Bye, Olaf.
 
Do not use an identity column for sequential numbers. Use a SEQUENCE object with the NOCACHE option.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top