逐条更新数据 sql

declare @tid int       
declare @fid int
declare @i int
declare @j int
set @j=(select count(*) from tbl1.dbo.dnt_topics)
set @i=1        
while   @i<@j        
begin            
    set @tid = (select tid from ( select ROW_NUMBER() over (order by tid asc ) as Row, tid,fid from dnt_topics ) as sp  where Row=@i)
    set @fid=(select fid from ( select ROW_NUMBER() over (order by tid asc ) as Row, tid,,fid from dnt_topics ) as sp  where Row=@i)                
    update            
        tbl2.dbo.dnt_topics         
    set                 
        fid=@fid        
    where             
        tid=@tid                    
        set @i=@i+1        
end
原文地址:https://www.cnblogs.com/swarb/p/9924288.html