首页 > 其他 > 详细

游标 cursor 分批更新表记录

时间:2021-03-11 17:39:09      阅读:18      评论:0      收藏:0      [点我收藏+]

server sql  400W的表,批量更新

declare @SecCode varchar(12)  
declare @sql_cmd varchar(2000)
declare sp cursor for
select SecCode from #STK_MKT_tmp where SecCode=SecCode
open sp
fetch next from sp into @SecCode
while(@@fetch_status=0)
BEGIn
	
	set @sql_cmd= ‘update  a 
 set  DEAL=b.DEAL,mtime=‘+‘‘‘2021-03-11 10:56:46.987‘‘‘+
 ‘ from  cgenius..STK_MKT a 
 left join s7.ginagao.dbo.STK_MKT_DEAL b 
 on a.tradedate=b.TRADEDATE and a.SecCode=b.STOCKCODE
 where a.DEAL is null  and ISVALID=1
 and  a.SecCode=‘+@SecCode

exec  ( @sql_cmd)
	fetch next from sp into @SecCode
END
close sp
deallocate sp

 

while 

 declare @a int,@b int
 set @a=1 
 while @a<22068549
 begin
     set @b=@a+1000
     insert into [tranconf_pp](S_TABNAME,PROCNAME,PARAM,UPDATEFIELD)
     select   ‘INDX_CLOSE_WEIGHT‘,‘DP_INDX_CLOSE_WEIGHT_2_C_INDX_CLOSE_WEIGHT‘,SEQ,‘‘
    FROM DATAPOOL..INDX_CLOSE_WEIGHT with (nolock)
    where seq between @a and @b
    set @a=@b+1
    --- waitfor delay ‘00:03:00‘
     truncate table  tranconf_pp 
 end

  

游标 cursor 分批更新表记录

原文:https://www.cnblogs.com/gina11/p/14517006.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!