File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes IDENTITY column in MySQL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "IDENTITY column in MySQL" Watch "IDENTITY column in MySQL" New topic

IDENTITY column in MySQL

JiaPei Jen
Ranch Hand

Joined: Nov 19, 2000
Posts: 1309
When we first create a table,
1. is it possible to create a column that identifies each record that is to be inserted?
2. If we can create this IDENTITY column, how do we create it? Do we set a maximum to the value of this column? Or the value simply increases as the number of records get inserted into the table grows?
3. when we try to insert the first record to this table, does this record go to the first row in the table? And the value of the IDENTITY for this record is 1? When we try to insert the second record to this table, does the second record automatically go to the second row in the table? And the value of the IDENTITY is 2? etc., etc.
Dmitry Melnik
Ranch Hand

Joined: Dec 18, 2003
Posts: 328
"An integer column may have the additional attribute AUTO_INCREMENT. When you insert a value of NULL (recommended) or 0 into an indexed AUTO_INCREMENT column, the column is set to the next sequence value. Typically this is value+1, where value is the largest value for the column currently in the table. AUTO_INCREMENT sequences begin with 1."
I agree. Here's the link:
subject: IDENTITY column in MySQL
It's not a secret anymore!