DBA

How to delete rows in a table are same identical rows in all the fields where clause column

Advertisements

How to delete rows in a table are same identical rows in all the fields where clause column. Recently, i got this from one of my friend.

 

create table tbl_delete (id int, name varchar(30))

insert into tbl_delete values (1,'Muthu')

insert into tbl_delete values (1,'Muthu')

insert into tbl_delete values (2,'SQL')

insert into tbl_delete values (2,'SQL')

-- Two rows are same with all fileds

select * from tbl_delete WHERE id =1

Begin tran

SET ROWCOUNT 1

DELETE FROM tbl_delete WHERE id =1

SET ROWCOUNT 0
-- Run this when you see (1 row(s) affected), otherwise rollback tran

Commit tran


Hope this help someone.

 

I’m currently working as a SQL server DBA in one of the top MNC. I’m passionate about SQL Server And I’m specialized in Administration and Performance tuning. I’m an active member of SQL server Central and MSDN forum. I also write articles in SQL server Central. For more Click here

Leave a Reply

Your email address will not be published. Required fields are marked *

+ 44 = 49