日度归档:2019年4月10日

mssql sqlserver高效删除数据的方法分享


摘要:
下文讲述sqlserver 高效删除数据的方法小记,如下所示:
实验环境:sql server 2008 R2


其实世界上根本没有高效删除数据的脚本,当我们对删除关联键添加了相应的索引,硬件进行了合理的规划后,高效删除数据的方法只有一条,那就是尽量将删除数据的脚本放入一个delete脚本中。
例:

 delete from tableName where keyId in (1,2,3,4,5,6)
 ----比下面的脚本要高效
 delete from tableName where keyId =1 ;

 delete from tableName where keyId =2 ;

 delete from tableName where keyId =3 ;

 delete from tableName where keyId =4 ;

 delete from tableName where keyId =5 ;

 delete from tableName where keyId =6 ;