Google+ Tools
Make Google+ profile picture
Make Google plus banners for profile
Create and share your Google Plus profile banners.

Profile image for mrk studios Ray Linder on March 10, 2009
Remove duplicate data from table in database
Language
SQL
Tags

Remove duplicate data from table in database


DECLARE @ID int
DECLARE @COUNT int

DECLARE CUR_DELETE CURSOR FOR
SELECT [ID],COUNT([ID]) FROM [Example] GROUP BY [ID],HAVING COUNT([ID]) > 1

OPEN CUR_DELETE

FETCH NEXT FROM CUR_DELETE INTO @ID,@COUNT
/* Loop through cursor for remaining ID */
WHILE @@FETCH_STATUS = 0
BEGIN

DELETE TOP(@COUNT -1) FROM [Example] WHERE ID = @ID

FETCH NEXT FROM CUR_DELETE INTO @ID,@COUNT
END

CLOSE CUR_DELETE
DEALLOCATE CUR_DELETE 

Comments

blog comments powered by Disqus