July 21, 2008 at 10:52 pm
Comments posted to this topic are about the item Deleting Duplicate batches of rows
July 21, 2008 at 11:23 pm
This code does not give proper results. I tried to work on this but its really untested bad work by the developer.
August 21, 2008 at 5:31 am
Ritesh what is it that is not working, can you let me know.
October 3, 2008 at 1:19 am
I think this is a much more efficient example for deleting duplicate rows using a single query and not having to resort to using Cursors:
http://dipakjpatel.blogspot.com/2007/08/delete-duplicate-rows-using-single.html
Regards
Nick
October 3, 2008 at 11:45 am
don't need a temp table. don't need cursors.
you can remove dups in one statement.
cheers.
October 3, 2008 at 12:17 pm
The code worked fine for me. There is more than one way to do this. So if you don't like this way try another but in terms of results this code works.
Francis
October 6, 2008 at 1:42 am
I am sure the code works fine, however the article implied that this is one situation where you have to use cursors - which are very inefficient if you can do it alternatively in a single query:
>>This code works in SQL Server 2005 and above, because it uses the delete top (N) statement. Although using a cursor is not always a good idea but there are situations where we have to use it.
I am sure the cursor method with copying the data to a temporary table is satisfactory for small sets of data. I was surprised however to see it listed as a featured article in SQL Server Central's daily newsletter. When having to regularly run a query against e.g. 1m+ records that may involve several tables, it helps to know if there are more efficient methods. I thought it was worth pointing to a more efficient method that I came across recently as this is not a situation where we have to use cursors.
Regards
Nick
October 7, 2008 at 2:23 pm
A much simpler way to remove duplicates would be to use SELECT DISTINCT * from tableName
October 8, 2008 at 1:23 am
SELECT DISTINCT * from tableName
While this gives you a list of records without the duplicates, it does not help much in deleting the duplicates. Additional code is still need to do something to remove the duplicates from the original table which this article addresses along with the other suggestions.
January 2, 2009 at 11:31 am
Thank you for sharing this. It was my introduction to cursors, and I was able to adapt it to keep my input table intact (by adding top(1) to another table, instead of deleting top @cnt).
Going forward, it does appear the common table expression approach linked by Nick has more promise.
All I wanted was something like 'Ignore row errors on insert'!
Viewing 10 posts - 1 through 9 (of 9 total)
You must be logged in to reply to this topic. Login to reply