如何在MySQL中进行批量插入 [英] How to do a batch insert in MySQL
本文介绍了如何在MySQL中进行批量插入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有1多个记录需要输入到表中。在查询中执行此操作的最佳方法是什么?我应该做一个循环,并插入一个记录每次迭代?或者有更好的方法吗?
I have 1-many number of records that need to be entered into a table. What is the best way to do this in a query? Should I just make a loop and insert one record per iteration? Or is there a better way?
推荐答案
从 MySQL手册
使用VALUES的INSERT语句
语法可以插入多行。要做
这个,包括列
列的多个列表,每个列在
括号内并用逗号分隔。
例如:
INSERT statements that use VALUES 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);
这篇关于如何在MySQL中进行批量插入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文