我说 100 行数据要插入到 MySQL 数据库表中。
但我不想写所有 100 个 INSERT
语句。
SQL中有批量插入语句吗???
如果可能,请帮助编写代码。
最佳答案
作为MySQL manual状态:
INSERT
statements that useVALUES
syntax can insert multiple rows. To do this, include multiple lists of column values, each enclosed within parentheses and separated by commas. Example:INSERT INTO tbl_name (a,b,c) VALUES(1,2,3),(4,5,6),(7,8,9);
此外,来自 speed of INSERT
的部分:
If you are inserting many rows from the same client at the same time, use
INSERT
statements with multipleVALUES
lists to insert several rows at a time. This is considerably faster (many times faster in some cases) than using separate single-rowINSERT
statements. If you are adding data to a nonempty table, you can tune thebulk_insert_buffer_size
variable to make data insertion even faster. See Section 5.1.3, “Server System Variables”.
关于mysql - 批量插入SQL语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10429348/