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