aspose file tools
The moose likes JDBC and the fly likes MySQL AUTO_INCREMENT column not uniform Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Reply Bookmark "MySQL AUTO_INCREMENT column not uniform" Watch "MySQL AUTO_INCREMENT column not uniform" New topic
Author

MySQL AUTO_INCREMENT column not uniform

Rujitha Patel
Greenhorn

Joined: Sep 07, 2006
Posts: 8
MySQL database AUTO_INCREMENT (INT type) columns are not increasing uniformly. Ther are increasing like 0,1,2,3,7,8,9,16,17,18...

Why this happens? Will there be any problems of having a non uniform of data column as a Primary Key? How can I have a uniformly AUTO_INCREMENT column?

Thank you.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

I would guess it is because the "missing" ids came when an insert operation failed or was aborted? e.g. the auto_increment functionality was triggered then the insert didn't happen.

I don't know how auto_imcrement works in mysql, but it is common for databases to implement primary key generation mechanisms with spaces between the ids. Oracle sequences for example are not uniform, nor are SQL Server identity columns. In both cases, it is the performance trade off gained by grabing an id a "safe" distance from the last one and the overhead required to keep the values contiguous.

That aside, these are surrogate keys and have no business meaning, so what they are does not matter. All that matters is they are unique and unchanging.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: MySQL AUTO_INCREMENT column not uniform
 
Similar Threads
Leaving any property unmapped to a column in Hibernate using annotation
How to create a sequence in MySql5.0
how to retrieve the new ID of the auto_increment column
Migrating Toplink/ADF application to MySQL
inserting data of two forms into two tables with same transaction id