Jari Mäkelä schrieb am Mittwoch, 22. August 2001, 11:31:01:
> Hi,
> in the manual there is this LAST_INSERT_ID() and it is what I actually need
> but there is some confusion over how to use it in many tables.
> <exerpt http://www.mysql.com/doc/O/D/ODBC_and_last_insert_id.html>
> Or, if you are just going to insert the ID into another table, you can do
> this:
> INSERT INTO foo (auto,text) VALUES(NULL,'text');
> INSERT INTO foo2 (id,text) VALUES(LAST_INSERT_ID(),'text');
> <exerpt http://www.mysql.com/doc/O/D/ODBC_and_last_insert_id.html>
> I have database where most of the data is entered at once to multiple
> tables and the linking reference is the ID of the main table. Would this
> command just take the first ID and use it in other tables or would it take
> it from the new id of the other tables?
> What I mean is, would this code use the ID of first insert in all inserts ?
> INSERT INTO foo (auto,text) VALUES(NULL,'text');
> INSERT INTO foo2 (id,auto1,text) VALUES(0,LAST_INSERT_ID(),'text');
> INSERT INTO foo3 (id2,auto2,text) VALUES(0,LAST_INSERT_ID(),'text');
> or would it take the first last_insert_id() from first line and second from
> second line?
I don't have the time to test it, but I would think that
LAST_INSERT_ID() should return the last autoincrement value of
the last insert, so if you have autoincrement columns to all your
tables, you won't get what you want or rather run into big
trouble :-(
You play safe if you stuff the first number you are interested in
into a variable of your program and use this one for all
subsequent inserts.
--
Herzlich
Werner
MySQL in Deutschland: Anpassung, Unterstützung, Schulung für Sie
__ ___ ___ ____ __
/ |/ /_ __/ __/ __ \/ / Dr. Werner Stürenburg <[EMAIL PROTECTED]>
/ /|_/ / // /\ \/ /_/ / /__ MySQL AB, Consultant
/_/ /_/\_, /___/\___\_\___/ Bielefeld, Germany
<___/ www.mysql.com +49-5224-997-407 Fax -409
---------------------------------------------------------------------
Before posting, please check:
http://www.mysql.com/manual.php (the manual)
http://lists.mysql.com/ (the list archive)
To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php