* Alan McDonald
> My task is to insert a new master record and several detail records within
> the one transaction.
>
> There is a foreign key on the detail table set to the unique key (autoinc)
> field of the master table.
>
> Inserting a master record, even with a special field value so
> that it can be
> quickly returned with the newly created primary key, so that I might then
> insert the detail records with this primary key as their foreign key, does
> not seem very reliable to me (as suggested a few days ago).
>
> There must be a more reliable way to do this under heavy traffic.
> I'm afraid
> I'm used to being able to grab a generator ID and using that
> (guaranteed to
> be unique) for both the primary key of the master and the foreign
> key of the
> detail records. Surely there is a good method for use with MySQL....?

Yes, there is. Check out the function LAST_INSERT_ID():

<URL: http://www.mysql.com/doc/en/Miscellaneous_functions.html >
<URL: http://www.mysql.com/doc/en/mysql_insert_id.html >

--
Roger


---------------------------------------------------------------------
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

Reply via email to