MySQL รองรับการเพิ่มข้อมูลหลายแถวในคำสั่ง INSERT เดียว โดยคั่นชุดค่าด้วยเครื่องหมายคอมมา
สร้างตาราง
mysql> CREATE TABLE DemoTable (
UserId INT,
UserName VARCHAR(20),
UserAge INT
);
เพิ่ม 4 แถวในคำสั่งเดียว
mysql> INSERT INTO DemoTable(UserId, UserName, UserAge)
-> VALUES (100,'John',25), (101,'Larry',24), (102,'Chris',22), (103,'Carol',27);
Query OK, 4 rows affected (0.16 sec)
Records: 4 Duplicates: 0 Warnings: 0
ดูข้อมูลที่เพิ่มแล้ว
mysql> SELECT * FROM DemoTable;
+--------+----------+---------+
| UserId | UserName | UserAge |
+--------+----------+---------+
| 100 | John | 25 |
| 101 | Larry | 24 |
| 102 | Chris | 22 |
| 103 | Carol | 27 |
+--------+----------+---------+
ข้อดี: เร็วกว่า INSERT หลายครั้ง เพราะลดการสื่อสารระหว่าง Client และ Server