Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 使用备份表分批执行高效更新_Sql_Sql Server_Sql Server 2008_Tsql_Sql Update - Fatal编程技术网

Sql 使用备份表分批执行高效更新

Sql 使用备份表分批执行高效更新,sql,sql-server,sql-server-2008,tsql,sql-update,Sql,Sql Server,Sql Server 2008,Tsql,Sql Update,我有一些数据是从表A备份的。因此,我通过以下方式做到了这一点:- select * into backuptable_tableA from tableA where column1= 'Value1' and column2 = 'Value2' 备份由大约185000行组成,如上所示,称为backuptable_table a 现在在tableA中,我需要用值'LAMK'更新1列(column1)。现在有谁能推荐一个高效的SQL查询,它可以批量更新tableA中的column1。比如说一次

我有一些数据是从表A备份的。因此,我通过以下方式做到了这一点:-

select * into backuptable_tableA from tableA
where column1= 'Value1' and column2 = 'Value2'
备份由大约185000行组成,如上所示,称为backuptable_table a

现在在tableA中,我需要用值'LAMK'更新1列(column1)。现在有谁能推荐一个高效的SQL查询,它可以批量更新tableA中的column1。比如说一次10000行?SQL应该在更新第一个10000后停止,然后我可以检查数据并执行下一个10000,以此类推。。。是否还要通过加入可备份的_表来确保它做到这一点?(为了便于讨论,我们假设tableA是column1、column2、column3和column4的唯一约束)

..或者我必须在执行备份时使用的更新中使用相同的参数吗


感谢过去使用while循环对我有用的东西

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

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