看看是否有其他进程阻塞了,比如占用了这个表,你的update就只能等待。甚至可能死锁了。 select * from sys.sysprocesses where blocked<>0 看看里面有没有数据,有就是阻塞了。
sp_who 看下你执行的更新有没有被阻塞。blk 列里是否有值
加个where条件一批一批更新试试,按你的现状貌似都没开始更新呢。
update tb set col='xx' where ... waitfor delay '00:00:20'
循环批次更新 declare @i int=5000 while (@i=5000) begin update tb set col='xx' where col is null set @i=@@ROWCOUNT waitfor delay '00:00:05' end若where无法避免重复更新,就创建临时表,记录更新过的主键
select * from sys.sysprocesses where blocked<>0
看看里面有没有数据,有就是阻塞了。
waitfor delay '00:00:20'
declare @i int=5000
while (@i=5000)
begin
update tb set col='xx'
where col is null
set @i=@@ROWCOUNT
waitfor delay '00:00:05'
end若where无法避免重复更新,就创建临时表,记录更新过的主键
这样一次连接里的循环,无法避免日志持续变大吧
不但waitfor没有用,曾经试过,就是用commit也会持续变大
BEGIN
UPDATE TOP(5000) dbo.LargeOrders
SET CustomerID = N'ABCDE'
WHERE CustomerID = N'OLDWO'; IF @@rowcount < 5000 BREAK;
END
GO
,也就是数据是分批写入的。而一条语句的话,整个更新就是一个事务,需要在全部完成之后才写入,性能区别是很大的