00 Votes

MySQL: Insert multiple records at once

Question by NetLabel | 2012-03-23 at 15:27

I have about 50 to 100 records to be inserted into a table with a PHP script. However, I do not want to call 50 times a new INSERT command after each other, which seems to me a little bit bad for the performace.

There must be a better and also faster way! Does any one of you have a solution?

00 Votes

You are right! Calling a hundred times an INSERT in a row makes little sense. The syntax, you are looking for is as follows:

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

Thus, it is much like a normal INSERT, you can easily attach more records with a comma separated.
2012-03-24 at 20:52

ReplyPositive Negative

Related Topics

Important Note

Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.


Ask your own question or write your own article on askingbox.com. That’s how it’s done.