MySQL: Limit of Rows Insertable in a Single INSERT Statement
The number of rows you can insert in a single INSERT statement in MySQL can be influenced by two key factors:
1. Value Sets:
No, the number of rows inserted is not directly dependent on the number of value sets. You can insert an arbitrary number of rows in a single INSERT statement, regardless of the number of columns or their respective values.
2. Statement Size:
Yes, the number of rows insertable can be limited by the size of the INSERT statement itself. MySQL has a configuration parameter called "max_allowed_packet" which specifies the maximum length of SQL statements that the server can receive from a client. If your INSERT statement exceeds this limit, it will be rejected by the server.
Alternative for Mass Insertion:
While the statement size limitation can be a constraint, there is an alternative way to insert a large number of rows efficiently:
INSERT ... SELECT:
The "INSERT ... SELECT" pattern allows you to insert rows from another table or a subquery into the destination table. This approach is not limited by the statement size and allows you to insert an arbitrarily large number of rows.
The above is the detailed content of How Many Rows Can You Insert in a Single MySQL INSERT Statement?. For more information, please follow other related articles on the PHP Chinese website!