If you're inserting multiple rows in the dependent table for the same id in the parent table, you'll need to save the value of LAST_INSERT_ID(), otherwise subsequent inserts will change it!
INSERT INTO parent VALUES (...);
INSERT INTO child1 VALUES (@id, ... );
INSERT INTO child2 VALUES (@id, ... );
From: Keith Clark [mailto:keithclark@stripped]
Sent: Friday, March 12, 2010 7:57 AM
Subject: Re: Nested inserts possible?
That seems to be the ticket. Thanks!
On Fri, 2010-03-12 at 16:54 +0100, Johan De Meersman wrote:
> Have a look at last_insert_id().
> On Fri, Mar 12, 2010 at 3:48 PM, Keith Clark
> <keithclark@stripped> wrote:
> I have two tables and I have data to insert into both at the
> same time,
> but the second table depends on an ID that is auto created in
> the first
> table. I'm not sure exactly how to accomplish this.
> MySQL General Mailing List
> For list archives: http://lists.mysql.com/mysql
> To unsubscribe:
> Bier met grenadyn
> Is als mosterd by den wyn
> Sy die't drinkt, is eene kwezel
> Hy die't drinkt, is ras een ezel
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/mysql?unsub=1
This message contains confidential information and is intended only for the individual named. If you are not the named addressee, you are notified that reviewing, disseminating, disclosing, copying or distributing this e-mail is strictly prohibited. Please notify the sender immediately by e-mail if you have received this e-mail by mistake and delete this e-mail from your system. E-mail transmission cannot be guaranteed to be secure or error-free as information could be intercepted, corrupted, lost, destroyed, arrive late or incomplete, or contain viruses. The sender therefore does not accept liability for any loss or damage caused by viruses or errors or omissions in the contents of this message, which arise as a result of e-mail transmission. [FriendFinder Networks, Inc., 220 Humbolt court, Sunnyvale, CA 94089, USA, FriendFinder.com