多次插入

INSERT multiple times

我需要在 MySQL 中插入多行。

像这样:

INSERT INTO  `table` ( `X` , `Y` , `Z`)VALUES (DEFAULT,  '1',  '1')
INSERT INTO  `table` ( `X` , `Y` , `Z`)VALUES (DEFAULT,  '2',  '2')
INSERT INTO  `table` ( `X` , `Y` , `Z`)VALUES (DEFAULT,  '3',  '3')

我收到这个错误:

1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'INSERT INTO table ( X , Y , Z ' at line 2

我尝试在每个插入的末尾使用 ;,,但没有。

您可以使用单独的查询

INSERT INTO  `table` ( `X` , `Y` , `Z`) VALUES (DEFAULT,  '1',  '1');
INSERT INTO  `table` ( `X` , `Y` , `Z`) VALUES (DEFAULT,  '2',  '2');
INSERT INTO  `table` ( `X` , `Y` , `Z`) VALUES (DEFAULT,  '3',  '3');

或仅查询

INSERT INTO  `table` ( `X` , `Y` , `Z`) VALUES 
 (DEFAULT,  '1',  '1'),(DEFAULT,  '2',  '2'), (DEFAULT,  '3',  '3');

;