Home >Database >Mysql Tutorial >Share a tutorial on inserting multiple records in batches using an insert statement
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:
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!