Home > Database > Mysql Tutorial > body text

How to batch insert multiple records in SQL insert?

coldplay.xixi
Release: 2020-06-23 13:22:25
Original
13338 people have browsed it

How to batch insert multiple records in SQL insert?

#How to batch insert multiple records in SQL insert?

How to insert multiple records in batches in sql:

Common insert statements, one statement 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 was 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:

How to batch insert multiple records in SQL insert?

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.

Recommended tutorial: "mysql video tutorial"

The above is the detailed content of How to batch insert multiple records in SQL insert?. 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