How expensive is select distinct * query

两盒软妹~` 提交于 2019-12-23 12:35:08

问题


In sql server 2012, I have got a table with more than 25 million rows with duplicates. The table doesn't have unique index. It only has a non-clustered index. I wanted to eliminate duplicates and so, I m thinking of the below

select distinct * into #temp_table from primary_table
truncate primary_table
select * into primary_table from #temp_table

I wanted to know how expensive is select distinct * query. If my procedure above is very expensive, I wanted to know if there is another alternate way.


回答1:


I don't know how expensive it is, but an alternate way is to create another table with a primary key, insert all the data there and silently reject the duplicates as stated here

http://web.archive.org/web/20180404165346/http://sqlblog.com:80/blogs/paul_white/archive/2013/02/01/a-creative-use-of-ignore-dup-key.aspx

basically, using IGNORE_DUP_KEY



来源:https://stackoverflow.com/questions/22163765/how-expensive-is-select-distinct-query

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!