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
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
When do you think a developer should use sql server-based cursors?
Define cross join in sql server joins?
What are the options which must be set to allow the usage of optimistic models?
How to use column default values in insert statements in ms sql server?
What are advantages of ssrs or why we should use ssrs?
What is explicit cursors?
Where sql server usernames and passwords are stored in a sql server?
How to handle error or exception in sql?
Do you think BCNF is better than 2NF & 3NF? Why?
Does partitioning help performance?
How to Update from select query in sql server?
What is the difference between varchar and varchar(max) datatypes?
explain different types of joins? : Sql server database administration
Explain the database you used in your final year project?