How to retrieve duplicate rows in a table?
How to delete the duplicate entries in a table?
Answer Posted / mohit d jethva
///////////Cursor for delete duplicate record in
table//////////
DECLARE @ID int
DECLARE @NAME NVARCHAR(50)
DECLARE @COUNT int
DECLARE CUR_DELETE CURSOR FOR
SELECT [ID],[NAME],COUNT([ID]) FROM [Example] GROUP BY [ID],
[NAME] HAVING COUNT([ID]) > 1
OPEN CUR_DELETE
FETCH NEXT FROM CUR_DELETE INTO @ID,@NAME,@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,@NAME,@COUNT
END
CLOSE CUR_DELETE
DEALLOCATE CUR_DELETE
Mohit D Jethva
| Is This Answer Correct ? | 7 Yes | 4 No |
Post New Answer View All Answers
Describe how to use linked server?
How to list all tables in the database using odbc_tables()?
What the different topologies in which replication can be configured?
How to drop existing indexes in ms sql server?
How to recompile stored procedure at run time?
Explain Normalization and DE normalization
Define inner join in sql server joins?
Explain about system stored procedure?
What happens if null values are involved in comparison operations?
explain extended properties
Write an SQL query to obtain the 2nd highest salary.
What are the disadvantages of using the stored procedures?
What structure can you implement for the database to speed up table reads?
What are SSL and TSL protocols?
Explain transaction server isolation?