MySQL Forums
Forum List  »  Newbie

Inserting into Multiple tables
Posted by: Carter Kuros
Date: July 11, 2005 02:00PM

I'm collecting information from a web form that I want to post into 4 different tables. There are 4 parts of the web form, each part will submit information into a different table. Each table is related to the others by a similar key "user_id"

I would like to post all 4 parts of the web form data to each of their corresponding tables with a single INSERT statement. Is this possible?

example:

Instead of

INSERT INTO Table_1 (userName, userPhone, userEmail) Value('Bill', '555-5555','this@emial.com') WHERE userID = '54';
INSERT INTO Table_2 (userName, userCompany, userCompanyPhone) Value('Bill', 'Big Bucks LLC', '555-5555') WHERE userID = '54';
INSERT INTO Table_3 (userName, userCar, userVIN) Value('Bill', 'Toyota','212342342342332') WHERE userID = '54';
INSERT INTO Table_4 (userName, userCellPhone, userHours) Value('Bill', '555-5555',9) WHERE userID = '54';


Can i just do one big insert like:

INSERT
INTO Table_1 (userName, userPhone, userEmail) Value('Bill', '555-5555','this@emial.com')
INTO Table_2 (userName, userCompany, userCompanyPhone) Value('Bill', 'Big Bucks LLC', '555-5555')
INTO Table_3 (userName, userCar, userVIN) Value('Bill', 'Toyota','212342342342332')
INTO Table_4 (userName, userCellPhone, userHours) Value('Bill', '555-5555',9)

WHERE userID = '54';

(I thought it would be better to do that then to seperated the query and run it 4 seperate times)

Thanks ahead of time!

Options: ReplyQuote


Subject
Written By
Posted
Inserting into Multiple tables
July 11, 2005 02:00PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.