Multiple Inserts with MySQL
Andy Jarrett posted this technique for insterting multiple rows (bulk insert) in one SQL statement a few months ago. It's a handy trick:
INSERT INTO x (a,b) VALUES ('1', 'one'), ('2', 'two'), ('3', 'three')
I tried that on a couple hundred thousand rows today, and I got an error that my statement was bigger than the Max Allowed Packet size in MySQL. So keep that in mind when using. You can either change the setting, or go about it a different way.
Like this? Follow me ↯Tweet Follow @pfreitag
Multiple Inserts with MySQL was first published on June 10, 2005.
If you like reading about mysql, databases, insert, bulk, or sql then you might also like:
- Insert Delayed with MySQL
- Sphinx - Open Source SQL Full Text Search Engine
- Updated SQL Reserved Words Checker
- MySQL FULLTEXT Indexing and Searching
- SQL to Select a random row from a database table
- SQL Reserved Key Words Checker Tool
- Order by NULL Values in MySQL, Postgresql and SQL Server
- Cheat Sheet for SQL Server