Saturday, December 10, 2011

Remove or delete duplicate records or rows from SQL Server Database.

You can delete or remove the duplicate records or rows from your SQL Database Table without needing identical column with following piece of code. I used single field or column in this example. If you have better solution, please kindly leave a comment. 



SELECT * INTO #TempTable FROM DTABLE GROUP BY DRECORD HAVING COUNT(DRecord)>1
DELETE FROM DTABLE
INSERT INTO DTABLE SELECT * FROM #TEMPTABLE
DROP TABLE #TEMPTABLE
SELECT * FROM DTABLE

















All the best!!!!

No comments:

Post a Comment