Gil Gil - 3 months ago 25
MySQL Question

INSERT multiple times

I need to insert multiple rows in MySQL.

Like this:

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')


I got this error:


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


I tried with
;
and
,
at the end of each insert, but nothing.

Answer

You can do with separeated query

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');

or with a query only

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

;