修改过的提交事务--注意的是语法必须通过编译

 declare @s varchar(8000)
  declare cu cursor for
  select '
  begin tran
  begin try
  exec
   (''
   update a
   set a.'+quotename(col)+'=null
   from '+quotename(db)+'.'+quotename(sch)+'.'+quotename(tbl)+' a
   where '+quotename(col)+'=''''''''
   '')
  if @@error=0
  begin
  commit tran
  print ''OK ! '+quotename(db)+'.'+quotename(sch)+'.'+quotename(tbl)+' change col :  '+quotename(col)+' success!''
  end
  else
  begin
  rollback tran
  print ''Error ! '+quotename(db)+'.'+quotename(sch)+'.'+quotename(tbl)+' change col :  '+quotename(col)+' fail!''
  end
  end try
  begin catch
  print ''语法Error ! '+quotename(db)+'.'+quotename(sch)+'.'+quotename(tbl)+' change col :  '+quotename(col)+' fail!''
  print error_message()
  rollback tran
  end catch
  ' from [master].[dbo].UnionALL
  where istochang=1  and spacenum<>0 and db<>'SSIStest'
open  cu
fetch next from cu into @s
while @@fetch_status=0
begin
exec(@s)
fetch next from cu into @s
end
close cu
deallocate cu

你可能感兴趣的:(修改过的提交事务--注意的是语法必须通过编译)