by

Remove Duplicate rows in SQL Server

This script removes the duplicate rows in table Customers detecting the rows with the same contactname
Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
src="https://www.snip2code.com/Embed/1036844/Remove-Duplicate-rows-in-SQL-Server?startLine=0"></iframe>
Click on the embed code to copy it into your clipboard Width Height
Leave empty to retrieve all the content Start End
SET NOCOUNT ON SET ROWCOUNT 1 WHILE 1 = 1 BEGIN DELETE FROM Customers WHERE contactname IN (SELECT contactname FROM Customers GROUP BY contactname HAVING COUNT(*) > 1) IF @@Rowcount = 0 BREAK ; END SET ROWCOUNT 0
If you want to be updated about similar snippets, Sign in and follow our Channels

blog comments powered by Disqus