Home  >  Article  >  Database  >  Mysql uses insert to insert multiple records and batch new data instance tutorial

Mysql uses insert to insert multiple records and batch new data instance tutorial

小云云
小云云Original
2017-12-25 13:27:491770browse

This article mainly introduces Mysql's use of insert to insert multiple records and add new data in batches. Friends who need it can refer to it. I hope it can help everyone.

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


INSERT INTO table1 (id,name) VALUES(1,小明,2,小强,3,小杜,4,小李,5,小白);

MySQL will throw the following error


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

The correct way of writing should be like this:


INSERT INTO t able1(i,name) VALUES(1,'小明'),(2,'小强'),(3,'小杜'),(4,'小李'),(5,'小白');

Of course, this way of writing can also omit the column name, so that each The number of values ​​in parentheses must match, and this number must match the number of columns. Such as:


INSERT INTO t able1 VALUES(1,'小明'),(2,'小强'),(3,'小杜'),(4,'小李'),(5,'小白');

Related recommendations:

MySQL uses INSERT to insert multiple records

MySql 3 tips for insert operation_MySQL

MySQL uses INSERT to insert multiple records_MySQL

The above is the detailed content of Mysql uses insert to insert multiple records and batch new data instance tutorial. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn