Answer the question
In order to leave comments, you need to log in
How to make multiple insert into 2 tables at once?
Hello!
Given:
There are table1 and table1_meta.
Relationship 1(table1) to many(table1_meta). By column table1_id
Task:
It is
necessary to make an insert in table1 and a lot of rows in table1_meta at once.
Questions:
How to make it most competently for insert 1 of the table1 row?
How to do it most competently for insert 10 rows of table1 ?
Thanks everyone for the replies.
Answer the question
In order to leave comments, you need to log in
At first you do insert 10 rows of table1 and only then set of rows in table1_meta.
You won't be able to insert directly into different tables. Only two requests.
wow-insert-in-one-query is called LOAD DATA INFILE - will insert values from a file. But in 1 table.
so 2 times - it is necessary.
It is possible to try
through triggers . But strongly depends on what data goes to the second table.
Perhaps it is possible through transactions.
Give examples of requests.
dev.mysql.com/doc/refman/5.6/en/optimizing-innodb-...
you need a plot:
SET foreign_key_checks=0;
... SQL import statements ...
SET foreign_key_checks=1;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question