如何在 MySQL 中进行批量插入

How to do a batch insert in MySQL(如何在 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 中进行批量插入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:如何在 MySQL 中进行批量插入

基础教程推荐