Hi,

I think what you need is an auto increment (primary key) column. When a record is inserted, it will automatically generate the next number in the sequence. Being a primary key, the column must be unique (i.e no two rows can be the same), so you can identify a specify record in the table. When you insert a record, you can run

SELECT LAST_INSERT_ID();

to retrieve the id that was used. The LAST_INSERT_ID is determined on a per connection basis, so you are guaranteed to get the last id that _you_ inserted, even if there are other users inserting records, as long as you do not run another INSERT.

As for 3, you should not worry about how MySQL stores the rows. You should specify an ORDER BY clause in your SELECT statements to get the order in which you want. If you want to know, MySQL stores the rows ascending (1 is first, 2 is second, ...). However, if a record gets deleted from the table, then MySQL will try to re-use the space that once held that row.

Check out the following links:
http://www.mysql.com/doc/en/CREATE_TABLE.html
http://www.mysql.com/doc/en/example-AUTO_INCREMENT.html

HTH

Matt

At 01:14 PM 12/23/2003, you wrote:
Hi, I am a beginner in using database.  And I
appreciate your support and help.

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?






__________________________________ Do you Yahoo!? New Yahoo! Photos - easier uploading and sharing. http://photos.yahoo.com/

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]



-- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]



Reply via email to