批量更新。A B 表 从表B 找不等于 A 的数据 并更新 A的数据=B的数据 A(a1,a2,a3) B(b1,b2,b3) 表 从表B 找不等于 A 的数据 并更新 因为有其它字段,所以不可以删除再插入的。

解决方案 »

  1.   

    可以想像关键字为a1,b1, 更新a2, a3咯,其它字段忽略
      

  2.   

    A(a1,a2,a3) a1主键
    B(b1,b2,b3)  b1主键如果A.a1=B.b1, 并且A.a2<>B.b2, A.a3<>b.b3
    更新A.a2=B.b2, A.a3=b.b3这下应该说明白了吧
      

  3.   

    update A set a2=(select b2 from B where b2<>A.a2 and b3<>A.a3 and b1=A.a1)
    , a3=(select b3 from B where b2<>A.a2 and b3<>A.a3 and b1=A.a1)
    where exist (select * from B where b2<>A.a2 and b3<>A.a3 and b1=A.a1)
      

  4.   

    当A.a2 <>B.b2, A.a3 <>b.b3 两条都满足时更新
    update A set a2=(select b2 from B where b2 <>A.a2 and b3 <>A.a3 and b1=A.a1) 
    , a3=(select b3 from B where b2 <>A.a2 and b3 <>A.a3 and b1=A.a1) 
    where exist (select * from B where b2 <>A.a2 and b3 <>A.a3 and b1=A.a1)当A.a2 <>B.b2, A.a3 <>b.b3 至少满足一条时更新
    update A set a2=(select b2 from B where (b2 <>A.a2 or b3 <>A.a3) and b1=A.a1) 
    , a3=(select b3 from B where (b2 <>A.a2 or b3 <>A.a3) and b1=A.a1) 
    where exist (select * from B where (b2 <>A.a2 or b3 <>A.a3) and b1=A.a1)
      

  5.   

    update a
       set a2 = (select b2
                   from b
                  where a.a1 = b.b1
                    and a.a2 <> b.b2
                    and a.a3 <> b.b3),
           a3 = (select b3
                   from b
                  where a.a1 = b.b1
                    and a.a2 <> b.b2
                    and a.a3 <> b.b3)