所以,我遇到了一些代码,这些代码应该可以帮助我通过批量更新一个庞大的表(100m+ 条记录),如下所示:
--Declare variable for row count
set rowcount 50000
go
Declare @rc int
Set @rc=50000
While @rc=50000
Begin
Begin Transaction
--Use tablockx and holdlock to obtain and hold
--an immediate exclusive table lock. This unusually
--speeds the update because only one lock is needed.
update MyTable With (tablockx, holdlock)
set TestField='ABC'
----Get number of rows updated
----Process will continue until less than 50000
select @rc=@@rowcount
Commit
End
问题是,这进入了一个无限循环,一直打印(受影响的 50000 行)直到结束。顺便说一句,如果表中的记录少于 50000 条,则上面的代码会正确退出。有人知道怎么修这个东西吗?
谢谢