The method of inserting multiple records and adding data in batches by using insert in Mysql
This article mainly introduces Mysql using insert to insert multiple records batch new data method, has a certain reference value, interested friends can refer to, I hope you read this article after a lot of gains, the following let Xiaobian take you to understand.
If you want to insert 5 records into table1, the following is incorrect:
INSERT INTO table1 (id,name) VALUES(1, Xiao Ming, 2, Xiao Qiang, 3, Xiao Du, 4, Xiao Li, 5, Xiao Bai);
MySQL will throw the following error
ERROR 1136: Column count doesn't match value count at row 1
The correct way to write it would be:
INSERT INTO t able1(i,name) VALUES(1,'Xiaoming'),(2,'Xiaoqiang'),(3,'Xiaodu'),(4,' Xiaoli'),(5,'Xiaobai');
Of course, column names can also be omitted in this way, so that the number of values in each pair of brackets must be the same, and this number must be the same as the number of columns. For example:
INSERT INTO t able1 VALUES(1,'Xiaoming '),(2,'Xiaoqiang'),(3,'Xiao Du'),(4,'Xiao Li'),(5,'Xiao Bai'); Thank you for reading this article carefully, I hope Xiaobian shared "Mysql uses insert to insert multiple records to add batch data method" This article is helpful to everyone, but also hope that everyone more support, pay attention to the industry information channel, more relevant knowledge waiting for you to learn!