Link to home
Start Free TrialLog in
Avatar of kingent85
kingent85Flag for United States of America

asked on

Mysql Multi Insert from Multi Tables

How can I write a mysql query that will insert into multiple tables from multiple tables. I know that you can select multiple tables and insert into a single one. I am trying to duplicate a customer that has an id in all of my tables. I simply want to make a copy of this customer data and update another customer. So the only thing changing is the ID.
Avatar of Patrick Matthews
Patrick Matthews
Flag of United States of America image

kingent85 said:
>>How can I write a mysql query that will insert into multiple tables from multiple tables.

You can't.  A single INSERT statement will only insert into one table.  You need to execute a separate
statement for each table you want to insert into.
Avatar of bmatumbura
bmatumbura

You can also use an INSERT Trigger on the table in which you are inserting the records. The trigger will then have to insert these new values into the additional tables
Avatar of kingent85

ASKER

can you give me an example of a trigger statement?
ASKER CERTIFIED SOLUTION
Avatar of bmatumbura
bmatumbura

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial