SqlServer——批量操作(批量添加,删除)批量添加数据:
⼀条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执⾏通过。
量插⼊数据了,遵循这样的语法,就可以批量插⼊数据了。
===================================================truncate删除数据
批量删除数据:
delete from table where id in (xxxxxxxx)
truncate table 表名;//彻底删除,再插⼊数据就会从1开始