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

How to send a ssrs report from ssis?

125


What is cte (common table expression)?

601


Give some Scenario for Non Clusterd index? Can we write system defined functions in side The Function? Wat is the Unique Datatype?

2087


How to create a scrollable cursor with the scroll option?

502


What is SQL Azure Fabric?

92






What are constraints in microsoft sql server?

565


Describe in brief authentication modes in sql server.

569


How raid can influence database performance?

578


How to update a field in SQL after ALTERING a row?

690


What is use of attribute hierarchy ordered ? : sql server analysis services, ssas

561


Does sql server 2000 clustering support load balancing?

572


Tell me what are cursors and when they are useful?

511


What is built-in function?

550


What is the current limitation of the size of SQL Azure DB?

102


as a general practice, it is recommended to have dbo be the owner of all database objects however, in your database you find number of tables owned by a user other than dbo, how could you fix this? : Sql server administration

538