日期:2014-05-17  浏览次数:20602 次

批量删除数据脚本问题
DECLARE @return_value int
DECLARE @id_value int
--DECLARE @id1 int
--DECLARE @id2 int
   
BEGIN  
set @id_value =1000 
WHILE @id_value < 3000 
   begin       
     SELECT 'Begin ID:' = @id_value  
       delete FROM       table WHERE     id<@id_value 
       commit
     SET @id_value = @id_value +1000  
   end  
END 
GO
以上是我的脚本,为何运行很长时间无法删除数据,直到超时,但
为何以下语句我单位执行就很快会处理完成
 delete FROM       table1  WHERE     id<1000 

还有一个问题就是是否可以在脚本的循环体内加打印输出项,这样可以了解到脚本还未运行完成的情况下,
就可以知道当前ID的值是多少?
批量删除数据脚本问题1

------解决方案--------------------
1、事物冲突。
2、print @id_value
------解决方案--------------------
不需要   commit
ORACLE才需要,MSSQL是隐式事务提交的,单个DELETE已经包含提交事务处理了。。。