Home  >  Article  >  Database  >  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

零下一度
零下一度Original
2017-05-18 15:52:2010616browse

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');

(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');

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!

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