Solved

SQL Server 2012 Identity Column Increases by 1000

Posted on 2015-02-11
10
77 Views
Last Modified: 2015-02-12
I have several SQL Server databases. I have hundreds of tables that use an Identity on the primary key to increment the value.

I upgraded to SQL Server 2012 about 6 months ago. Twice since the upgrade, my Identity value has jumped by around 1000.

I have hundreds of tables that use the identity column, but the jump has only occurred on a couple of the higher use tables. For example, the Return Order table, has twice jumped by around 1000 places.

As a programmer, a number is a number and I could really care less, but the end users don't like to see that two sequential orders are numbered 8001 and then 9001.

Can anyone explain why this is happening and what can be done to prevent it in the future?
0
Comment
Question by:yonbret
10 Comments
 
LVL 65

Expert Comment

by:Jim Horn
ID: 40603470
The most likely cause is that rows were inserted between 8001 and 9000 and then deleted.
Identity values do not automatically 're-seed' when rows are deleted.

Just out of curiosity, explain why users are seeing this id field, and why they would care?  
The answer will affect a couple of workarounds we can provide.
0
 
LVL 47

Expert Comment

by:Vitor Montalvão
ID: 40603482
orders are numbered 8001 and then 9001.
Is just a guess but can be a composed value here? Like 8 + 001 and 9 + 001?
Another guess is there is some process that insert and then deletes some rows and being an identity column will let gaps.
You can post here the table definitions so we can see better how we can help you.
0
 

Author Comment

by:yonbret
ID: 40603585
They are not deleted rows and are not composed values.

I found this article on the issue, but I want some confirmation that this solution will actually work:

http://www.codeproject.com/Tips/668042/SQL-Server-Auto-Identity-Column-Value-Jump-Is
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 47

Expert Comment

by:Vitor Montalvão
ID: 40603597
Very interesting. Specially the part "Microsoft declares it is a feature rather than a bug and in many scenarios it would be helpful."

First time I'm hearing this. But SEQUENCES are a good solution. It's been used by ORACLE for years already.
0
 

Author Comment

by:yonbret
ID: 40603612
Has any one used the -t272 option found in the article?

I don't have the time to transform hundreds of identity columns to sequence columns.
0
 
LVL 47

Accepted Solution

by:
Vitor Montalvão earned 500 total points
ID: 40603619
By this article I think it works.
0
 
LVL 69

Expert Comment

by:Scott Pletcher
ID: 40603639
You need to fully understand the performance hit you're taking by doing this.

You'd be better off telling the users that it's just an arbitrary number and that it's never guaranteed to be truly sequential.

Rollbacks can also cause gaps in the numbers, although a rollback of 1000 rows would be unheard of for a lot of tables.
0
 

Author Comment

by:yonbret
ID: 40603659
We sell a low volume, high dollar product so I think we will be alright performance wise, but I will monitor the performance.
0
 
LVL 35

Expert Comment

by:David Todd
ID: 40604071
Hi,

I have a small database with a table or two with identities. I've seen this occur when moving the database between workstations, or upgrading it.

That would fit with your comment that you upgraded 6 months ago.

HTH
  David
0
 
LVL 48

Expert Comment

by:PortletPaul
ID: 40605285
It absolutely should not matter, to any human, if there are non-contiguous unique identities.
If humans seriously do get upset by this there is a design fault.

On your own head be it, I vote against.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question