现在有一表B,我每天从A插入数据,为了避免插入重复数据,需要做判断。
用not exits 是不是不行,他会完全阻止插入?
我要达到的目标是,重复的记录不插,不重复的仍然插,比如插入100条,发现重复2条,那应该继续插入98条,那怎么做?

解决方案 »

  1.   

    --A,B表结构一样的话。select * from B
    except
    select * from A 
      

  2.   

    1.B表里 建主键或者唯一索引。
    2. insert into B select distinct * from A
      

  3.   

    插入之前你先把不重复的数据给筛选出来,不行吗?insert into B select 字段 from A where A.id not in (select ID from B)