By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,053 Members | 1,595 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,053 IT Pros & Developers. It's quick & easy.

Inserting into multiple tables using Auto Incremented Field

P: n/a
I'm inserting a record into MySQL 4.0 using Visual Basic ADO. When
using the AddNew and Update method I am unable to retrieve the value
of a Auto incrment field (Yes I know I can MoveLast but this icreases
the update time by a factor of 10 and when your talking about 200,000
inserts its way to long). Is there a way to insert the record into
multiple tables in one statement where you can use the value of the
auto incremented field as the key in the second table? So the
statement inserts the record into a table retrieves the new
auto_incremented key and then insterts information into the second
table using the incremented key as the primary key? Thanks
Jul 20 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Ryan Hubbard wrote:
inserts its way to long). Is there a way to insert the record into
multiple tables in one statement where you can use the value of the
auto incremented field as the key in the second table? So the


This is possible only with (atleast) two queries.
INSERT INTO foo (auto,text) VALUES(NULL,'text');
INSERT INTO foo2 (id,text) VALUES(LAST_INSERT_ID(),'text');

http://dev.mysql.com/doc/mysql/en/OD...insert_id.html

Jul 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.