我有两个表,表的结构是相同的,现在我想把一个表中的内容写到另外一个表中,同时还要判断写入的那个表是否存在与当前写入的记录相同的记录,应该怎么实现?
谢谢

解决方案 »

  1.   

    table1:源表
    table2:目標表insert into table2(field1,field2,......)
        select field1,field2,......
        from table2 
        where field1 not in (select distinct field1 from table1)
      

  2.   

    insert into table2
        (select * from table2 
        where field1 not in (select distinct field1 from table1))
      

  3.   

    insert into table2
        (select * from table2 
        where field1 not in (select distinct field1 from table1))
    外星人 的就可以了 。UP
      

  4.   

    前台实现,还是后台实现;
    是oracle数据库,还是sqlserver数据库;insert /*+append */ into a select * from b;//平行插入,很快
    然后检验是否有重复记录,用如下语句:
    select 字段 from a group by 字段 having count(*)>1;
    如果有重复的,删掉即可效率很高