CREATEtableMultipleRecordWithValues->(->idint,->namevarchar(100)->);QueryOK,0rowsaffected(0.88sec) The following is the syntax for batch insertion. INSERTintoyourTableNamevalues(column1,column2,....N"> How to do bulk insert in MySQL?-Mysql Tutorial-php.cn

How to do bulk insert in MySQL?

王林
Release: 2023-08-31 09:33:12
forward
1455 people have browsed it

How to do bulk insert in MySQL?

To do bulk insert, we need to use all column names with brackets and separated by ",".

Let's look at an example. First, we will create a table. Following is the CREATE command to create a table.

mysql> CREATE table MultipleRecordWithValues - > ( - > id int, - > name varchar(100) - > ); Query OK, 0 rows affected (0.88 sec)
Copy after login

The following is the syntax for batch insertion.

INSERT into yourTableName values(column1,column2,....N),(column1,column2,....N),(column1,column2,....N),...........N;
Copy after login

Apply the above syntax to insert batch records.

mysql> insert into MultipleRecordWithValues values(1,'John'),(2,'Carol'),(3,'Bob'),(4,'Smith'); Query OK, 4 rows affected (0.16 sec) Records: 4 Duplicates: 0 Warnings: 0
Copy after login

Since 4 rows are affected, this means we have successfully inserted the record. To check whether all records exist in the table, use the SELECT command.

mysql> select *from MultipleRecordWithValues;
Copy after login

The following is the output.

+------+-------+ | id | name | +------+-------+ | 1 | John | | 2 | Carol | | 3 | Bob | | 4 | Smith | +------+-------+ 4 rows in set (0.00 sec)
Copy after login

The above is the detailed content of How to do bulk insert in MySQL?. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!