Emma Emma - 6 months ago 14
SQL Question

Inserting multiple rows in mysql

Is the database query faster if I insert multiple rows at once:

like

INSERT....

UNION

INSERT....

UNION


(I need to insert like 2-3000 rows)

Answer

INSERT statements that use VALUES syntax can insert multiple rows. To do this, include multiple lists of column values, each enclosed within parentheses and separated by commas.

Example:

INSERT INTO tbl_name
    (a,b,c)
VALUES
    (1,2,3),
    (4,5,6),
    (7,8,9);

Source

Comments