Mysql uses insert to insert multiple records to add data in batches

Mysql uses insert to insert multiple records to add data in batches

If you want to insert 5 records into table1, the following is wrong:

INSERT INTO table1 (id,name) VALUES(1,Xiaoming,2,Xiaoqiang,3,Xiaodu,4,Xiaoli,5,Xiaobai);

MySQL will throw the following error

ERROR 1136: Column count doesn't match value count at row 1

The correct way to write it should be like this:

INSERT INTO table1(i,name) VALUES(1,'Xiao Ming'),(2,'Xiao Qiang'),(3,'Xiao Du'),(4,'Xiao Li'),(5,'Xiao Bai');

Of course, you can also omit the column name in this way, so the number of values ​​in each pair of brackets must be the same, and this number must be consistent with the number of columns. like:

INSERT INTO table1 VALUES(1,'Xiao Ming'),(2,'Xiao Qiang'),(3,'Xiao Du'),(4,'Xiao Li'),(5,'Xiao Bai');

Summarize

The above is what I introduced to you about using insert in Mysql to insert multiple records in batches of new data. I hope it will be helpful to you. If you have any questions, please leave me a message and I will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website!

You may also be interested in:
  • Examples of 4 methods for inserting large amounts of data in MySQL
  • MYSQL batch insert data implementation code
  • Tutorial on implementing batch inserts in MySQL to optimize performance
  • How to avoid MySQL batch inserts with unique indexes
  • Detailed example code of mysql batch insert loop
  • MySQL batch insert data script
  • Detailed explanation of MySQL batch SQL insert performance optimization
  • MySql batch insert optimization Sql execution efficiency example detailed explanation
  • MySQL batch inserts data through function stored procedures

<<:  How to Set Shortcut Icons in Linux

>>:  js to upload pictures to the server

Recommend

Introduction to the use and difference between in and exists in MySQL

First put a piece of code for(int i=0;i<1000;i...

Basic knowledge of HTML: a preliminary understanding of web pages

HTML is the abbreviation of Hypertext Markup Langu...

Summary of commonly used escape characters in HTML

The commonly used escape characters in HTML are s...

Analysis of the use and principle of Docker Swarm cluster management

Swarm Cluster Management Introduction Docker Swar...

Mysql backup multiple database code examples

This article mainly introduces the Mysql backup m...

Implementation of Docker container connection and communication

Port mapping is not the only way to connect Docke...

Native JS to implement drag position preview

This article shares with you a small Demo that ad...

How to use css overflow: hidden (overflow hiding and clearing floats)

Overflow Hide It means hiding text or image infor...

What you need to know about creating MySQL indexes

Table of contents Preface: 1. Create index method...

How to find the specified content of a large file in Linux

Think big and small, then redirect. Sometimes Lin...

Two ways to start Linux boot service

Table of contents rc.local method chkconfig metho...

In-depth understanding of Vue's plug-in mechanism and installation details

Preface: When we use Vue, we often use and write ...