MySQL数据库中insert如何批量插入多条记录? MySQL数据库使用教程

凤凰 2021-1-19 73 1/19

MySQL数据库中insert如何批量插入多条记录? MySQL数据库使用教程

sql中insert如何批量插入多条记录?

sql中insert批量插入多条记录的方法:

常见的insert语句,向数据库中,一条语句只能插入一条数据:

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

(如上,仅插入了一条记录)

怎样一次insert插入多条记录呢?

使用示例:

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

这样就批量插入数据了, 遵循这样的语法,就可以批量插入数据了。

执行成功,截图:

MySQL数据库中insert如何批量插入多条记录? MySQL数据库使用教程

据说,在程序开发中,一次插入多条数据,比逐次一条一条的插入数据,效率高很多

所以在程序开发的时候,使用此批量插入,也是比较不错的。

此语句在MySQL 5, postgreSQL 9.3执行通过。

推荐教程:《mysql视频教程》

以上就是sql中insert如何批量插入多条记录?的详细内容,更多请关注本站其它相关文章!

- THE END -
Tag:

凤凰

1月19日09:22

最后修改:2021年1月19日
0

非特殊说明,本博所有文章均为博主原创。