删除重复记录的完整解决方案

Posted on 2007-05-29 08:59  秋雨飘飘  阅读(192)  评论(0编辑  收藏  举报
将重复的记录记入temp1表:
select [标志字段id],count(*) into temp1 from [表名]
group by [标志字段id]
having count(*)>1

2、将不重复的记录记入temp1表:
insert temp1
select [标志字段id],count(*) from [表名]
group by [标志字段id]
having count(*)=1

3、作一个包含所有不重复记录的表:
select * into temp2 from [表名]
where 标志字段id in(select 标志字段id from temp1)

4、删除重复表:
delete [表名]

5、恢复表:
insert [表名]
select * from temp2

6、删除临时表:
drop table temp1
drop table temp2

Copyright © 2024 秋雨飘飘
Powered by .NET 8.0 on Kubernetes