您的位置:首页 > 数据库

SQL语句快速删除重复记录

2008-04-21 17:17 323 查看
declare @counts int
declare @id int

select ThreadID, count(*) as Counts into tempTable from [ArchivedMSDNThreads]
group by ThreadID
having count(*)>1 order by count(*) desc

while exists (select * from tempTable)
begin
select top(1) @counts = Counts,@id = ThreadID from tempTable
delete top(@counts - 1) from [ArchivedMSDNThreads] where ThreadID = @id
delete top(1) from tempTable
end

drop table tempTable
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: