how to delete duplicate rows from table in sql server

Answer Posted / onlymoid

CREATE TABLE dbo.duplicateTest ------Deleting
Duplicates with same id
(
[ID] [int] ,
[FirstName] [varchar](25),
[LastName] [varchar](25)
) ON [PRIMARY]

INSERT INTO dbo.duplicateTest VALUES(1, 'Bob','Smith')
INSERT INTO dbo.duplicateTest VALUES(2, 'Dave','Jones')
INSERT INTO dbo.duplicateTest VALUES(3, 'Karen','White')
INSERT INTO dbo.duplicateTest VALUES(1, 'Bob','Smith')



SELECT * FROM dbo.duplicateTest

SET ROWCOUNT 1
DELETE FROM dbo.duplicateTest WHERE ID = 1
SET ROWCOUNT 0

SELECT * FROM dbo.duplicateTest

Drop table dbo.duplicatetest

Is This Answer Correct ?    5 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How to create “dependant” parameter “make, model, year”

89


what is datawarehouse?

653


What do you understand by recursive stored procedures?

572


What is always encrypted?

521


What are the new security features added in sql server 2012? : sql server security

536






hi, how to link a text file and a .rpt file in my tables of sql server and to retrieve those records for further use. reply me as soon as possible.

1564


What is query and its types?

516


How to create a Master database in SQL server ?

554


Create a dts package to produce a text file using the ‘update statistics’ command for the tables in a database with obsolete statistics.

536


sql database suspect We have a sql database that is showing as suspect. How can we recover?

1408


Write a code to select distinct records without using the DISTINCT keyword.

652


Explain how long are locks retained within the repeatable_read and serializable isolation levels, during a read operation with row-level locking?

664


how can u get last observation in an unknown dataset ?

2003


Tell me about the approaches which you used to counter the DI problems.

769


Beginning with sql server version 7 0, a new enhanced data type nchar was added what type of data is supported with this data type?

524