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 are the different types of lock modes in sql server 2000?

496


I have a table Events Events containing cardno,time,id,name--each id has a cardno my requirement is every day each employee swipe the card several times i want to calculate first and last time of each card the output should be name 1 2 6 7 in out in out holiday holiday xxx 09:30 06:30 09:40 06:45 where 1,2...... are dates for example january 1,2, etc. 6 and 7 are saturday and sunday how it is posssible

1801


Can we store videos inside the sql server table?

527


How to test subquery results with the exists operator?

571


You have a stored procedure, which execute a lengthy batch job. This stored procedure is called from a trigger you do not want to slow the data entry process you do not want trigger to wait for this batch job to finish before it completes itself what you can do to speed up the process?

656






How to perform backup for certificates in sql server? : sql server security

602


Do you know what are various aggregate functions that are available?

531


What are sql server functions?

524


What is bcp? When does it used?

555


Explain full-text query in sql server?

545


What were the latest updates to SQL Azure service?

94


What is the purpose of the tempdb database?

581


How to disconnect from a sql server using mssql_close()?

595


What is RMS migrations?

1711


How do you test your database? : sql server database administration

533