Home > Database > Mysql Tutorial > Share a tutorial on inserting multiple records in batches using an insert statement

Share a tutorial on inserting multiple records in batches using an insert statement

零下一度
Release: 2017-05-18 15:52:20
Original
10654 people have browsed it

One insert statement inserts multiple records in batches

Common insert statements can only insert one piece of data into the database:

insert into persons 
(id_p, lastname , firstName, city )
values(204,'haha' , 'deng' , 'shenzhen');
Copy after login

(as above, only one record is inserted)

How to insert multiple records at one time?

Usage example:

insert into persons 
(id_p, lastname , firstName, city )
values
(200,'haha' , 'deng' , 'shenzhen'),
(201,'haha2' , 'deng' , 'GD'),
(202,'haha3' , 'deng' , 'Beijing');
Copy after login

In this way, data can be inserted in batches. By following this syntax, data can be inserted in batches.

Successful execution, screenshot:

Share a tutorial on inserting multiple records in batches using an insert statement

It is said that in program development, inserting multiple pieces of data at one time is much more efficient than inserting data one by one.

So it is good to use this batch insertion during program development.

This statement is executed in MySQL 5 and postgreSQL 9.3.

【Related Recommendations】

1. Analysis of the three commonly used insert statements in mysql and their differences

2. Share insert into Tips for statement optimization

The above is the detailed content of Share a tutorial on inserting multiple records in batches using an insert statement. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template