还是作业调度方面的
现在有若干个表,表a,表b,表b...表n
然后每个表里面都有ID字段,del字段(值为“是”或者“否”表明该字段是否被删除)
现在每天定时在一定条件下,把表a里面的一些数据的del字段改为“是”以后,要求把这些数据在其他表里面的del字段也同步改为“是”(这些表的ID字段都是共同的)
我个人感觉是不是应该用临时表和inner join来配合完成?但是我不知道具体该怎么写,望高人指教~

解决方案 »

  1.   

    先把a表更新掉,然后用子查询update 表 set del='是' where id in(select id from a where del='是')
      

  2.   

    就是update触发器,条件是del字段被更新,不过对于性能要求高的场合不太适合用触发器
      

  3.   

    好,我去找下trigger的资料看下先~
      

  4.   

    如果不要实时用作业也行update b 
    set del='是' 
    from tb b 
    where exists(select 1 from ta where b.id = id and del='是')如果实时是可以用trigger来实现 
    create trigger t_update
    on ta
    for update
    as
    begin
    if update(del)
       update b 
       set del='是' 
       from tb b 
       where exists(select 1 from inserted where b.id = id and del='是')
    end 
    go