none
Deleting duplicates values of a given column when there is no primary key using ADO.NET RRS feed

  • Question

  • Hi,

    I have a situation where there is a SQL Server table that has no keys and has to columns say x and y.

    I want to delete all rows having duplicate values in the x column but keep only 1.

    I need to do this using ADO.NET.

    Since the table has no key, I was wondering if there is a way to loop through a result set, identify the duplicate programatically by comparing the current x value to the last read x value, then issue a delete.

    This would work if there were a "cursor" concept in ADO.NET but the only thing close to this is the SQLReader which does not have a cursor so the delete will not know the exact record to delete.

    Could you provide some insight on this...?

     

    Thanks.

    Saturday, March 27, 2010 3:01 PM

Answers

  • Is it possible to introduce a unique key of some sort into the sql server's table (autoincrement?)? Otherwise you might want to do it within a stored procedure...
    Miha Markic [MVP C#] http://blog.rthand.com
    Saturday, March 27, 2010 3:48 PM

All replies