Without a primary key there's no fast easy way to do this. You'll need to handle each one, one at a time.
If you are using SQL 2000 or below you'll need to do something like this.
<pre>SET ROWCOUNT 1
DELETE FROM YourTable
WHERE Col1 = 'Something'
AND COl2 = 'SomethingElse'
/*Add what ever filters are needed to isolate the duplicate row*/</pre>
If you are using SQL 2005 or above you'll ned to do something like this.
<pre>
DELETE TOP (1) FROM YourTable
WHERE Col1 = 'Something'
AND COl2 = 'SomethingElse'
/*Add what ever filters are needed to isolate the duplicate row*/</pre>
Last Wiki Answer Submitted: August 14, 2008 7:22 pm by Denny Cherry64,550 pts.
All Answer Wiki Contributors: Denny Cherry64,550 pts.
If you live outside the United States, by submitting your email address you consent to having your personal data transferred to and processed in the United States.
I ran into this issue recently and solved it using a select distinct statement against all the columns to make a new table with unique rows as a materialized query. In my case I was then able to confirm the contents of the new table, delete the original and rename the new table. It would be more complicated if there are dependencies on the table, though.
Check out my SQL Server blog “SQL Server with Mr Denny” for more SQL Server information.
I ran into this issue recently and solved it using a select distinct statement against all the columns to make a new table with unique rows as a materialized query. In my case I was then able to confirm the contents of the new table, delete the original and rename the new table. It would be more complicated if there are dependencies on the table, though.
SELECT DISTINCT (column1, column 2, column 3, column 4,…, column n)
FROM Table
I’d also recommend adding a primary key.