sql-server – 从大数据集中删除重复项(gt; 100Mio行)
我知道这个主题在此之前出现了很多次,但是没有一个建议的解决方案适用于我的数据集,因为我的笔记本电脑由于内存问题或完全存储而停止计算. 我的表看起来如下,并有108 Mio行: Col1 |Col2 | Col3 |Col4 |SICComb | NameComb Case New |3523 | Alexander |6799 |67993523| AlexanderCase New Case New |3523 | Undisclosed |6799 |67993523| Case NewUndisclosed Undisclosed|6799 | Case New |3523 |67993523| Case NewUndisclosed Case New |3523 | Undisclosed |6799 |67993523| Case NewUndisclosed SmartCard |3674 | NEC |7373 |73733674| NECSmartCard SmartCard |3674 | Virtual NetComm|7373 |73733674| SmartCardVirtual NetComm SmartCard |3674 | NEC |7373 |73733674| NECSmartCard 唯一列是SICComb和NameComb.我尝试添加一个主键: ALTER TABLE dbo.test ADD ID INT IDENTITY(1,1) 但整数只是在新的分钟内填满了超过30 GB的存储空间. 哪个是从表中删除重复项的最快最有效的方法? 解决方法通常,从表中删除重复项的最快方法是将记录(无重复项)插入临时表,截断原始表并将其重新插入.以下是使用SQL Server语法的想法: select distinct t.* into #temptable from t; truncate table t; insert into t select tt.* from #temptable; 当然,这在很大程度上取决于第一步的速度.而且,您需要有空间来存储同一个表的两个副本. 请注意,创建临时表的语法因数据库而异.有些人使用create table的语法而不是select into. 编辑: 您的身份插入错误很麻烦.我认为您需要从distinct列的列表中删除标识.或者做: select min(<identity col>),<all other columns> from t group by <all other columns> 如果您有一个标识列,则没有重复项(根据定义). 最后,您需要确定行所需的ID.如果您可以为行生成新的id,那么只需将标识列从插入列列表中删除: insert into t(<all other columns>) select <all other columns>; 如果您需要旧的标识值(并且最小值可以),请关闭标识插入并执行: insert into t(<all columns including identity>) select <all columns including identity>; (编辑:ASP站长) 【免责声明】本站内容转载自互联网,其相关言论仅代表作者个人观点绝非权威,不代表本站立场。如您发现内容存在版权问题,请提交相关链接至邮箱:bqsm@foxmail.com,我们将及时予以处理。 |
-
无相关信息