Mysql: is there any way to make "INSERT INTO" tables 2?

I have one table with two columns that I want to split into two tables:

table Columns: user_id, col1, col2

New tables:

B: user_id, col1

C: user_id, col2

I want to do:

INSERT INTO B (user_id, col1) SELECT user_id,col1 from A;
INSERT INTO C (user_id,col2) SELECT user_id, col2 from A;

But I want to do this in one statement. The table is large, so I just want to do it in one pass. Is there any way to do this?

thank.

+3
source share
4 answers

No, you cannot insert multiple tables at the same time. The syntax INSERTallows only one table name.

http://dev.mysql.com/doc/refman/5.5/en/insert.html

INSERT [LOW_PRIORITY | Detained | HIGH_PRIORITY] [IGNORE] [INTO] tbl_name [...

+1
source

.

+1

" " "" - , , , - - , :

START TRANSACTION;
INSERT INTO B (user_id, col1) SELECT user_id,col1 from A;
INSERT INTO C (user_id,col2) SELECT user_id, col2 from A;
COMMIT;

, , @lexu.

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

: MyISAM ( ), InnoDB.

+1

, /, , IO.

An attempt to insert into two tables at once (even if it was possible) is likely to increase the total insertion time, since there will be more disk space than writing to your tables.

0
source

Source: https://habr.com/ru/post/1789168/