How to delete a particular row from a table in SQL.

Who is online?  0 guests and 0 members
Home  »  Blogs  »  Anil  »  How to delete a particular row from a table in SQL.
Surendra likes this.
 
0
/5
Avg: 0/5: (0 votes)

Comments (2)

Micwed
Micwed said:
Hi Anil, nice idea. But I think you've forgot an PARTITON BY. In your example you get only ROwNumber = 1,2,3,4.... So for example on the AdventureWorks DB for DimCustomer if you looking for First and Lastname duplicates. I would like write it like this WITH newtbl as(SELECT *, 'row number'=Row_Number() over (PARTITION BY FirstName, LastName order by FirstName) FROM dbo.DimCustomer) DELETE FROM newtbl WHERE [row number]=2 Then you get every were RowNumber = 1 an only on the Firstname,Lastname duplicates RowNumber = 2. Cheers
1/31/2012
 · 
 
by
Anil
Anil said:
well, I have said that ,the script has been tested within the TestDatabase of CustomerList table having duplicate records.As per your info,AdventureWorks DB for DimCustomer has Primary key on 'Customerkey' which doesn't allows the duplicate records but the script you propose is also correct.
2/2/2012
 · 
 
by
Blogs RSS Feed

Anil's latest blog posts

Blogs RSS Feed

Latest community blog posts