Write a query to delete duplicate records in SQL SERVER

Answer Posted / rama krishna

This will help u a lot bcz dynamically it will delete
duplicates



create table tbl1 (col1 int)





insert into tbl1 values(1)
insert into tbl1 values(1)
insert into tbl1 values(1)
insert into tbl1 values(2)
insert into tbl1 values(2)
insert into tbl1 values(2)
insert into tbl1 values(2)
insert into tbl1 values(3)
insert into tbl1 values(3)


select * from tb1


set rowcount 1
select 'start'

while @@rowcount > 0
delete a from tbl1 a where (select count(*) from tbl1 b
where a.col1 = b.col1)>1
set rowcount 0
select * from tbl1
set nocount off

Is This Answer Correct ?    23 Yes 9 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Describe and explain about SQL native client?

610


Why truncate is ddl command?

512


How to verify the port number of the sql server?

551


What is the default server name for sql server?

634


Explain “not null constraint” in sql server?

522






What are the restrictions that views have to follow? : SQL Server Architecture

527


What are the types of lock supported by ?

608


Can we use max in where clause?

509


What is tablix?

115


What is the use of @@spid?

570


How do you know if sql server is running on your local system?

538


How to use subqueries with the exists operators in ms sql server?

584


How can delete duplicate records in cte in sql server?

512


Why SQL Agent is used?

594


Can we call future method from trigger?

505