Monday 12 November 2018

MySQL - how many rows can I insert in one single INSERT statement?

Does it depend on the number of values sets? Does it depend on the number of bytes in the 
INSERT statement?

 Answers


You can insert infinitely large number of records using INSERT ... SELECT 
pattern, provided you have those records, or part of, in other tables.
But if you are hard-coding the values using INSERT ... VALUES pattern, then 
there is a limit on how large/long your statement is: max_allowed_packetwhich limits
 the length of SQL statements sent by the client to the database server, and it affects 
any types of queries and not only for INSERT statement.



Query is limited by max_allowed_packet in general.



You can insert an infinite number of rows with one INSERT statement.

For example, you could execute a stored procedure that has a loop executed a

thousand times, each time running an INSERT query.

Or your INSERT could trip a trigger which itself performs an INSERT. Which trips

another trigger. And so on.

No, it does not depend on the number of value sets. Nor does it depend on the

number of bytes.

There is a limit to how deeply nested your parentheses may be, and a limit

to how long your total statement is. 



You will hit the max_allowed_packet limit and
error: 1390 Prepared statement contains too many placeholders.
You can put 65535 placeholders in one sql.So if you have two columns in one row,
you can insert 32767 rows in one sql.

0 comments:

Post a Comment