Deleting Duplicate Records from a Table

— SQL Server 2005 

–1.Using CTE with RowNum function

 –2. Using Set RowCount Command

SELECT * FROM dbo.duplicateTest

SET ROWCOUNT 1

DELETE FROM dbo.duplicateTest WHERE ID = 1

SET ROWCOUNT 0

SELECT * FROM dbo.duplicateTest

 –3. Using Top Command

SELECT * FROM dbo.duplicateTest

DELETE TOP(1) FROM dbo.duplicateTest WHERE ID = 1

SELECT * FROM dbo.duplicateTest

 –4. 

DELETE TOP (SELECT COUNT(*) 1 FROM dbo.Emptest WHERE EmpID = ‘Basharat’) FROM dbo.Emptest  WHERE EmpID = ‘Basharat’

 –5. Using Duplicate table and by renaming it ( Work in both Sql2000 & SQL 2005 )

Advertisements

Tags:

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: