1

I have say 100 rows data to insert in MySQL database table.
But i dont want to write all 100 INSERT statements.
Is there any bulk insert Statement in SQL ??? Please help with code if possible.

2 Answers 2

3

As the MySQL manual states:

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

Furthermore, from the section on speed of INSERT:

If you are inserting many rows from the same client at the same time, use INSERT statements with multiple VALUES lists to insert several rows at a time. This is considerably faster (many times faster in some cases) than using separate single-row INSERT statements. If you are adding data to a nonempty table, you can tune the bulk_insert_buffer_size variable to make data insertion even faster. See Section 5.1.3, “Server System Variables”.

Sign up to request clarification or add additional context in comments.

Comments

2
INSERT INTO tbl (col1, col2) VALUES ('val1', 'val2'), ('val3', 'val4'), ...

And please read documentation first next time

2 Comments

Sorry, actually I dint deleted it. I just modified the query as code parts.
@Sai Kalyan Akshinthala: ah, got it. We made 2 edits in the same time, and yours was first, sorry

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.