一条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');
登录后复制

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

执行成功,截图:

分享一条insert语句批量插入多条记录教程-LMLPHP

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

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

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

【相关推荐】

1. 解析mysql中常用的三种插入语句及其区别

2. 分享insert into语句优化的小技巧

以上就是分享一条insert语句批量插入多条记录教程的详细内容,更多请关注Work网其它相关文章!

09-07 06:35