大家好!我有一个数据库,里边有十万条数据,数据间有间隔(也就是缺号),而且还有重复的ID。请问大家怎么才可以消除重号,并且完全重新按数序排序。谢谢了~

解决方案 »

  1.   

    借用一临时表.select px = identity(int,1,1) , * into tmp from tb order by id 
    select * from tmp
      

  2.   

    将重复id号的查出,放到其它表中,再处理此数据,删除有重复id号的数据,再将处理好的数据插入原来的表中
    再将id号设为主鍵。取出重复id号记录的操作
    select * into 保存的表名称 from 表 as A
     where exists(select count(*) from 表 where id=a.id having count(*)>1)删除重复id号的记录
    delete A from 表 as A
     where exists(select count(*) from 表 where id=a.id having count(*)>1)