Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql server 2008 违反主键-重复数据消除表_Sql Server 2008 - Fatal编程技术网

Sql server 2008 违反主键-重复数据消除表

Sql server 2008 违反主键-重复数据消除表,sql-server-2008,Sql Server 2008,我有一个包含1000万条记录的表,其中一列上有一个非聚集索引键,我正在尝试对该表进行重复数据消除。我用select尝试了插入,其中要么使用左连接,要么不存在;但每次我都会得到违反密钥的错误。以下是我使用的查询 insert into temp(profile,feed,photo,dateadded) select distinct profile,feed,photo,dateadded from original as s where not exists(select 1 from

我有一个包含1000万条记录的表,其中一列上有一个非聚集索引键,我正在尝试对该表进行重复数据消除。我用select尝试了插入,其中要么使用左连接,要么不存在;但每次我都会得到违反密钥的错误。以下是我使用的查询

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 

我想,
distinct
没有像您预期的那样工作,因为时间部分会略有不同

另一种方法是使用
group by
并使用最早的
dateadded
删除任何重复项

也许是这样的:

Select Profile,
       Feed,
       Photo,
       Min(DateAdded) as [DateAdded]

From Original
Group By Profile, Feed, Photo

我想,
distinct
没有像您预期的那样工作,因为时间部分会略有不同

另一种方法是使用
group by
并使用最早的
dateadded
删除任何重复项

也许是这样的:

Select Profile,
       Feed,
       Photo,
       Min(DateAdded) as [DateAdded]

From Original
Group By Profile, Feed, Photo

迁移到?迁移到?我认为这可能正在工作,因为它现在正在运行,并且还没有停止错误消息。完成后将发回。谢谢,我认为这可能只是工作,因为它现在正在运行,还没有停止错误消息。完成后将发回。谢谢