views:

44

answers:

2

assuming that i have two tables, names and phones and i want to insert data from some input to the tables, in one query- How can it be done?

Please, if it can be done, explain the syntax.

+2  A: 

MySQL doesn't support multi-table insertion in a single INSERT statement. Oracle is the only one I'm aware of that does, oddly...

INSERT INTO NAMES VALUES(...)
INSERT INTO PHONES VALUES(...)
OMG Ponies
And there you have it
LittleBobbyTables
+1  A: 

You can't. However, you CAN use a transaction and have both of them be contained within one transaction.

BEGIN TRANSACTION;
insert into table_one values ('1','2','3');
insert into table_two values ('bob','smith');
COMMIT;

http://dev.mysql.com/doc/refman/5.1/en/commit.html

Joshua Smith