批量添加數據:
一條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執行通過。
量插入數據了, 遵循這樣的語法,就可以批量插入數據了。
===================================================
批量刪除數據:
delete from table where id in (xxxxxxxx)
truncate table 表名;//徹底刪除,再插入數據就會從1開始