AutoIncrement does not yield sequential numbers

rocatis
Member Posts: 163
I have a strange and somewhat worrying problem with a customer's Change Log: the Entry No. field is not sequential. This field has the (SQL) attribute AutoIncrement=Yes.
The problem has occurred twice, both times across dates. I suspect both have happened in conjunction with a server reboot.
30-09-14: Entry No. = 11192
01-10-14: Entry No. = 21191
A couple of weird things about this that are probably random, is that the the gap is 9999 and that the first and last digit are swapped.
05-01-15: Entry No. = 26388
06-01-15: Entry No. = 36367
This time the gap is 9979.
It's impossible for the gaps to have occurred because entries in the log have been deleted.
The customer (and in particular their accountant) more or less demands an explanation of this problem which I find totally reasonable. My problem is that at the moment my best reply is that it's SQL Server that is maintaining that field and that the problem must somehow be related to the (assumed) server reboots.
Can anyone come up with something better?
The problem has occurred twice, both times across dates. I suspect both have happened in conjunction with a server reboot.
30-09-14: Entry No. = 11192
01-10-14: Entry No. = 21191
A couple of weird things about this that are probably random, is that the the gap is 9999 and that the first and last digit are swapped.
05-01-15: Entry No. = 26388
06-01-15: Entry No. = 36367
This time the gap is 9979.
It's impossible for the gaps to have occurred because entries in the log have been deleted.
The customer (and in particular their accountant) more or less demands an explanation of this problem which I find totally reasonable. My problem is that at the moment my best reply is that it's SQL Server that is maintaining that field and that the problem must somehow be related to the (assumed) server reboots.
Can anyone come up with something better?
Brian Rocatis
Senior NAV Developer
Elbek & Vejrup
Senior NAV Developer
Elbek & Vejrup
0
Comments
-
Do not forget that uncommited transactions (ending with error) will allocate the number from the sequence, but entry will not exists because transaction was cancelled (rolled back). It means, Autoincrement does not guarantee continuous row by definition...
Of course, another "why" could be that entries are deleted, than you need to check the permissions (who has delete permissions on the table) and who has access to the SQL directly.0 -
kine wrote:Do not forget that uncommited transactions (ending with error) will allocate the number from the sequence, but entry will not exists because transaction was cancelled (rolled back). It means, Autoincrement does not guarantee continuous row by definition...
Besides, it's simply impossible that the table should have almost 10000 uncommitted transactions - twice. Bear in mind that the numbers tell us that around 5000 entries are created over a three month period.Of course, another "why" could be that entries are deletedBrian Rocatis
Senior NAV Developer
Elbek & Vejrup0 -
Sometimes there could be code calling the functionality.0
-
kine wrote:Sometimes there could be code calling the functionality.
Anyways, I found the answer: it's a "feature" in SQL Server: http://www.codeproject.com/Tips/668042/SQL-Server-2012-Auto-Identity-Column-Value-Jump-Is. In other words, if you want to make sure you're dealing with an unbroken sequence of entries, do not use AutoIncrement.Brian Rocatis
Senior NAV Developer
Elbek & Vejrup0 -
rocatis wrote:kine wrote:Sometimes there could be code calling the functionality.
But I am happy that you have found the reason, very interesting, I have not met it yet, but I am sure I will...
:thumbsup:0 -
Why would these gaps be worrisome? The entry number is just a number, it doesn't have any meaning. it's quite common for tables to have a single integer field as a primary key, which frees you up to change the data integrity rules of the table in any way way you want
Also when you insert 1000 records, and the auto increment sits at 1000, and then you delete all records, SQL Server will issue the next number at 1001. It doesn't care about keeping the sequence intact.rocatis wrote:In other words, if you want to make sure you're dealing with an unbroken sequence of entries, do not use AutoIncrement.0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions