批量插入

admin4年前php1019

一条insert语句批量插入多条记录

原创|浏览:138554|更新:2017-12-19 08:21

一条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 5, postgreSQL 9.3执行通过。


相关文章

面向过程的php sqlhelp

<?php $servername = "localhost"; $username = "root"; $...

短地址生成,全套配置教程

短地址生成,全套配置教程

nginx 配置location / {rewrite  ^(.*)$  /index.php?s=/$1  last;}code rotoo.top.7z...

php下载地址

https://windows.php.net/downloads/releases/archives/...

php替换ASCIII码空格字符的方法

需要用到PHP自带函数chr()方法如下:$string=str_replace(chr(0x01),"",$string);...

mysql批量添加数据

$conn=new sqlhelper;for ($i = 0; $i <1000 ; $i++) {$sql="insert into system_user(user_shenfe...

PHP里面将int型数据转换成日期输出以及将date型数据输出

        echo date('Y-m-d',$date); PHP里面将date型数据输出: echo $date; PHP里面将dat...

发表评论    

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。