Please give me queries for the following
1. To get the count of duplicate records.
2. A query to delete the duplicate records.
Answer Posted / srikanth
1. use group by clause with the field on which you want to
check for duplicates
Ex: select salary,count (*) from employee group by salary
having count (*)>1
2. Use the below query to delete the duplicate records (not
the original ones)
SET ROWCOUNT 1
DELETE yourtable
FROM yourtable a
WHERE (SELECT COUNT(*) FROM yourtable b WHERE b.name1 =
a.name1 AND b.age1 = a.age1) > 1
WHILE @@rowcount > 0
DELETE yourtable
FROM yourtable a
WHERE (SELECT COUNT(*) FROM yourtable b WHERE b.name1 =
a.name1 AND b.age1 = a.age1) > 1
SET ROWCOUNT 0
| Is This Answer Correct ? | 5 Yes | 0 No |
Post New Answer View All Answers
Explain in brief about Microsoft SQL server?
How to create a view and a stored procedure in ms sql server using "create view/procedure" statements?
Describe in brief system database.
What are indexes in ms sql server?
What is a unique key constraint?
What happens if ntwdblib.dll is missing on your machine?
What is the difference between Clustered and Non-Clustered Index?
Explain the dbcc pintable command when would you use it?
How do you Implement SSIS Packages in your Project?
What is the use of tempdb? What values does it hold?
Define cross join in sql server joins?
What is the process of normalising?
What is format parameter in ssrs?
what is an extended stored procedure? Can you instantiate a com object by using t-sql? : Sql server database administration
Can you give me some DBCC command options?(Database consistency check) - DBCC CHECKDB - Ensures that tables in the db and the indexes are correctly linked.and DBCC CHECKALLOC - To check that all pages in a db are correctly allocated. DBCC SQLPERF - It gives report on current usage of transaction log in percentage. DBCC CHECKFILEGROUP - Checks all tables file group for any damage.