aspose file tools*
The moose likes JDBC 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
Bookmark "IDENTITY column in MySQL" Watch "IDENTITY column in MySQL" New topic
Author

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
Quote:
"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."
Source: http://www.mysql.com/doc/en/CREATE_TABLE.html
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: IDENTITY column in MySQL