Write a query to delete duplicate records in SQL SERVER

Answer Posted / sagun sawant

Name Age
chandran 23
ranjith 24
chandran 23

To delete one of the duplicate records use following query

(For sql server 2000)

Set rowcount 1
delete from [tableName] order by name
set rowcount 0
--Write a cursor to delete multiple duplicate records
Or (In sql server 2005)

;with DelDup as (select row_number() over (partition by
sname order by sname) as RONO ,sname from [TableName])
Delete from DelDup where RONO > 1

Is This Answer Correct ?    29 Yes 11 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is mean by dml?

539


What method is used by the Command classes to execute SQL statements that return single values?

605


Name 3 ways to get an accurate count of the number of records in a table?

577


you notice that the transaction log on one of your databases is over 4gb the size of the data file is 2mb what could cause this situation, and how can you fix it? : Sql server administration

548


What options are there to delete rows on the publisher and not on the subscriber? : sql server replication

681






How do you run a trace?

522


What does normalization do to data?

548


How do I run a trace in sql server?

503


Do you know what is difference between index seek vs. Index scan?

522


How to download and install the scaled-down database adventureworkslt?

608


What are the new data types are introduced in sql 2000?

506


What is scalar user-defined function?

553


What is the difference between the application object and session object?

600


What are the events recorded in a transaction log?

508


Why I am getting "the microsoft .net framework 2.0 in not installed" message?

514