Insert SQL statement

I will say 100 rows of data to insert into the MySQL database table.
But I do not want to write all 100 INSERT statements.
Is there a bulk insert of Statement in SQL ??? Please help with the code if possible.

+1
source share
2 answers
 INSERT INTO tbl (col1, col2) VALUES ('val1', 'val2'), ('val3', 'val4'), ... 

And read the documentation next time

+2
source

As a guide to MySQL, it is indicated:

Operators

INSERT that use the VALUES syntax can insert multiple rows. To do this, include several lists of column values, each of which is enclosed in parentheses and separated by commas. Example:

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

Also, from the INSERT speed section:

If you are inserting many rows from the same client at the same time, use INSERT with multiple VALUES lists to insert multiple rows at a time. This is significantly faster (in many cases faster) than using separate single-line INSERT . If you are adding data to a non-empty table, you can configure the variable bulk_insert_buffer_size to make data insertion even faster. See Section 5.1.3, β€œServer System Variables” .

+2
source

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


All Articles