Inserting multiple rows in mysql

Emma picture Emma · Jul 31, 2011 · Viewed 826.4k times · Source

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

Nicola Cossu picture Nicola Cossu · Jul 31, 2011

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