Page 1 of 1

Know the autoincremental ID before insert

Posted: Wed 02 Mar 2005 00:51
by ben
Hello, is it possible to know the auto incremental ID before doing the insert? Just to display in the user interface what is the next ID.

Thanks

Posted: Wed 02 Mar 2005 09:03
by Ikar
Not, MySQL doesn't provide such functionality.

Posted: Wed 02 Mar 2005 23:39
by ben
Well, it supports:

show table status like 'tablename' and read the "Auto_increment" field.

Posted: Thu 03 Mar 2005 12:34
by Ikar
In the interval between this query and Post execution it might be an insertion of records from another client

Posted: Thu 03 Mar 2005 19:25
by ben
yes thats why you are doing a LOCK TABLE before. Anyway my application is single user.

Posted: Fri 04 Mar 2005 10:58
by Ikar
Your solution most likely will work.