删除重复的,只留一条:alter table 表 add  newfield int identity(1,1)delete 表
where newfield not in(
 select min(newfield) from 表 group by 你原来的关键字
                     )alter table 表 drop column newfield

解决方案 »

  1.   

    我现在用的是insert into dest_table select * from source_table
    这样的话,source_table如果有关键字和dest_table相同的记录,也会进入到dest_table里面么?这样不是违反了数据库关键字的唯一性?BTW:我的关键字是两个字段的组合。
      

  2.   

    会,你改为:
    insert into dest_table select * from source_table where 关键字 not in (selct 关键字 from dest_table)
      

  3.   

    两个字段的组合:insert dest_table select * from source_table where not exists (select 1 from dest_table where 关键字1=source.关键字1 and 关键字2=source.关键字2)
      

  4.   

    我的关键字是两个字段的组合,应该怎么写?
    比如说关键字为:A和B
    应该写成:
    insert into dest_table select * from source_table where A,B not in (selct 关键字 from dest_table)???
    这样好像不对的说。
      

  5.   

    insert dest_table select * from source_table where not exists (select 1 from dest_table where 关键字1=source.关键字1 and 关键字2=source.关键字2)如果你的主键确实是两个列的话应该不会出错,你贴出错误提示,和你的结构。