tags:

views:

180

answers:

2

I was wondering if there is a more efficient way of doing an insert in MySQL against multiple tables than a separate insert query for each record in each table. I was thinking of doing something like this:

INSERT INTO table1 
  (t1c1, t1c2, t1c3), table2 (t2c1, t2c2, t2c3) 
VALUES
  ('t1c1', 't1c2', 't1c3', 't2c1', 't2c2', 't2c3');

The reason for this is that the data is collated on a remote machine and will be doing the insert over the network.

A: 

You could insert into one table first, then into the second one from the first table:

INSERT INTO table1 ....
VALUES(....

INSERT INTO table2(....
SELECT ...
FROM table1 
WHERE ....
Brimstedt
Would this not mean a duplication of data between the tables? The program on the remote machine is not a database and both tables are on the remote database server.
aHunter
+1  A: 

No, there is no way of doing this in a single step. You will need to perform multiple queries.

soulmerge
Could I not use a view to link the tables and then insert into the view?
aHunter
Not even this is possible, unfortunately. I have been searching for this feature myself for a very long time :/
soulmerge
No problem thanks anyway.
aHunter