Showing posts with label acctnumber. Show all posts
Showing posts with label acctnumber. Show all posts

Sunday, February 19, 2012

for deleting duplicate rows subquery or cueser is Better in performance?

For deleting duplicate rows, i can use cursor and subquery.

cursor code

Declare dup_cursor cursor for
select acctnumber from LinkUrnABSADMBAR
group by acctnumber
having count(*) > 1

Open dup_cursor

Fetch Next from dup_cursor INTO @.acctnumber

While (@.@.Fetch_Status = 0)
Begin

Delete from LinkUrnABSADMBAR
where acctnumber = @.acctnumber

Fetch Next from dup_cursor INTO @.acctnumber
End

Close dup_cursor
Deallocate dup_cursor

Subquery code

delete from galupload2000..test where id in (select id from galupload2000..test group by id having count(*) >1)

My question is which one is Better in performance?

Thanks

Sandipan

Subqueries run faster than cursors as a general rule.

BobP

|||Thanks Bob