Hi Folks, needs a little advice.

I have a table that contains a unique auto-incrementing primary key
called 'id' (eg 1,2,3,4...).   When inserting data, I let mySQL allocate
the value that goes into this field. 

Now I want to insert a new row into this table and get the 'id' value
that mySQL has allocated (so I can then do some more work such as
attaching a filename called 'id'.xxx).

Can someone suggest a good way to do this ?  I thought of maybe doing a
"SELECT MAX(id) FROM table" first and then using id+1 as the new 'id'
for the next entry but this is frought with danger as someone could come
along and insert a new entry between my SELECT and INSERT.

Because 'id' is the only guaranteed unique column, I cannot think of a
way to do a SELECT after an INSERT to get back the 'id' of the last
thing inserted.

Can anyone help ?

Matt


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

Reply via email to