有表A和表B的表结构完全一致,A,B中有部分数据相同,如何把A中的数据追加插入到B表中?即,如果A表中的数据x在B表存在,不插入,如果不存在则插入B表。
   

解决方案 »

  1.   

    trucate table b
    insert into b
    select * fro a
      

  2.   

    insert b select a.* from a left join b on a.key=b.key where b.key is null
      

  3.   

    insert B select * from A where not exists(select 1 from B where a.x=b.x)
      

  4.   

    insert into b select * from a
      

  5.   

    --2005
    insert b select * from A except select * from b
      

  6.   

    insert B select * from A where not exists(select 1 from B where a.x=b.x)
      

  7.   


    insert b select * from a except select * from bexcept--是找出表A中有的表B中没有的数据
      

  8.   

    insert B select * from A where not exists(select 1 from B where A.主键字段1=B.主键字段1 and A.主键字段2 = B.主键字段2 and.....)