日期:2014-05-18  浏览次数:20434 次

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

------解决方案--------------------
借用一临时表.

select px = identity(int,1,1) , * into tmp from tb order by id 
select * from tmp

------解决方案--------------------
将重复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)