zoukankan      html  css  js  c++  java
  • 逐条更新数据 sql

           前些天更新数据时,update语句之后没加Where语句,结果更新后数据结果都是一样了,麻烦了,幸好有备份的数据,但想了想,不用数据库的还原功能应该也可以吧,用SQL语句应该可以还原的。     于是,就写了个SQL语句,供不小心,忘记更新数据少加Where语句的朋友看看 。
    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  
  • 相关阅读:
    快速幂和矩阵快速幂-模板
    gcd-模板+最小公倍数
    manacher-模板-hd-3068
    kmp-模板-hd-1711
    链式前向星-邻接表--模板
    poj-3096-Suprising Strings
    hihocoder-1615-矩阵游戏II
    hihocoder-Week174-Dice Possibility
    论文-Swish: A self-gated Active Function
    hihocoder-1595-Numbers
  • 原文地址:https://www.cnblogs.com/ruolinzhanyuan/p/1238367.html
Copyright © 2011-2022 走看看