我有一个包含1000万条记录的表,其中一列上有一个非聚集索引键,我正在尝试对该表进行重复数据删除。我尝试使用select插入where where,或者使用左连接,或者where not exists;但是每次我都得到违反键的错误。以下是我使用的查询;
insert into temp(profile,feed,photo,dateadded)
select distinct profile,feed,photo,dateadded from original as s
where not exists(select 1 from temp as t where t.profile=s.profile) 这只会产生键错误的违例。我尝试使用以下代码:
insert into temp(profile,feed,photo,dateadded)
select distinct profile,feed,photo,dateadded from original as s
left outer join temp t on t.profile=s.profile
where t.profile is null 我结束了使用批插入,因为日志文件变得太大了,但仍然得到了主键错误的冲突,即使只有1000条记录。
Destination Table :IX_Temp - profileUrl(ASC)--> unique key (non clustered)
Source Table: IX_PURL - profileUrl(ASC) ---> index (non clustered, not unique 发布于 2012-03-29 21:37:13
我想distinct在这里不会像你预期的那样工作,因为时间部分会略有不同。
一种不同的方法是使用group by并采用最早的dateadded来删除任何重复项。
可能是这样的:
Select Profile,
Feed,
Photo,
Min(DateAdded) as [DateAdded]
From Original
Group By Profile, Feed, Photohttps://stackoverflow.com/questions/9926418
复制相似问题