mysql - 批量插入SQL语句

标签 mysql batch-file bulkinsert

我说 100 行数据要插入到 MySQL 数据库表中。
但我不想写所有 100 个 INSERT 语句。
SQL中有批量插入语句吗??? 如果可能,请帮助编写代码。

最佳答案

作为MySQL manual状态:

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);

此外,来自 speed of INSERT 的部分:

If you are inserting many rows from the same client at the same time, use INSERT statements with multiple VALUES lists to insert several rows at a time. This is considerably faster (many times faster in some cases) than using separate single-row INSERT statements. If you are adding data to a nonempty table, you can tune the bulk_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/

相关文章:

windows - 对于批处理文件中的循环和 delims

postgresql - AWS Redshift 批量插入 + 编码定义

mysql - 如何计算基于 3 个表的 SQL

mysql - QueryBuilder 和子条件

MYSQL - 限制超过计数大小的记录数量

powershell - 在 PowerShell 中创建批处理作业

batch-file - 如果批量使用GTR/LSS运算符

c# - 将通用列表 C# 批量插入 SQL Server

sql-server - 使用格式文件(固定宽度)批量插入 - 遇到意外的文件结尾

php - DEFINER =`coinstourb_admin` @`localhost` *//