使用备份进行高效的批量更新 table

Doing an efficient update in batches using Backup table

我有一些数据是从 tableA 备份的。所以我通过执行以下操作来做到这一点:-

select * into backuptable_tableA from tableA
where column1= 'Value1' and column2 = 'Value2'

备份包含大约 185,000 行,如上所示称为 backuptable_tableA

现在,在表 A 中,我需要使用值 'LAMK' 更新 1 列 (column1)。现在任何人都可以建议一个有效的 SQL 查询,它可以批量更新 tableA 中的 column1。假设一次有 10,000 行? SQL 应该在更新前 10,000 次后停止,然后我可以检查数据并执行接下来的 10,000 次等等......无论如何确保它通过加入 backuptable_tableA 来做到这一点? (为了论证,我们假设 tableA 作为 column1、column2、column3 和 column4 的唯一约束)。

..或者我是否必须在进行备份时使用的更新中使用相同的参数?

谢谢

过去使用 while 循环对我有用的东西 https://msdn.microsoft.com/en-gb/library/ms178642.aspx

set rowcount 10000
declare @rc int
set @rc =1 
while @rc !=0
begin

  update TableA set column1 = 'LAMK'
    where column1 != 'LAMK'
      and column2  = ... 
      and column3  = ... 
      and column4  = ...
  select @rc = @@rowcount
end
go

您可以在循环内添加检查并根据需要回滚事务。

HTH