Rya*_*ter 2 sql sql-server duplicate-data sql-delete
这是一次冒险.我从上一个问题中的循环重复查询开始,但每个循环将覆盖所有1700万条记录,这意味着需要几周时间(仅运行*select count * from MyTable*需要我的服务器4:30分钟使用MSSQL 2005).我从这个网站和这篇文章中发现了一些信息.
并且已经到达下面的查询.问题是,对于任何类型的性能,这是在1700万条记录上运行的正确类型的查询吗?如果不是,那是什么?
SQL QUERY:
DELETE tl_acxiomimport.dbo.tblacxiomlistings
WHERE RecordID in
(SELECT RecordID
FROM tl_acxiomimport.dbo.tblacxiomlistings
EXCEPT
SELECT RecordID
FROM (
SELECT RecordID, Rank() over (Partition BY BusinessName, latitude, longitude, Phone ORDER BY webaddress DESC, caption1 DESC, caption2 DESC ) AS Rank
FROM tl_acxiomimport.dbo.tblacxiomlistings
) al WHERE Rank = 1)
Run Code Online (Sandbox Code Playgroud)
看到QueryPlan会有所帮助.
这可行吗?
SELECT m.*
into #temp
FROM tl_acxiomimport.dbo.tblacxiomlistings m
inner join (SELECT RecordID,
Rank() over (Partition BY BusinessName,
latitude,
longitude,
Phone
ORDER BY webaddress DESC,
caption1 DESC,
caption2 DESC ) AS Rank
FROM tl_acxiomimport.dbo.tblacxiomlistings
) al on (al.RecordID = m.RecordID and al.Rank = 1)
truncate table tl_acxiomimport.dbo.tblacxiomlistings
insert into tl_acxiomimport.dbo.tblacxiomlistings
select * from #temp
Run Code Online (Sandbox Code Playgroud)