Triggers deleting duplicate rows using T-sql Programming

This sample code snippet shows how triggers deleting duplicate rows using T-sql Programming.


Declare @id int,@name varchar (50),@cnt int,@roll_no numeric

Declare getall cursor local static For
Select count (1), id, name, roll_no
from t_name1 (nolock)
group by id, name,roll_no having count(1)>1
Open getall
Fetch next from getall into @cnt,@id,@name,@roll_no
While @@fetch_status=0
Begin
Set @cnt= @cnt-1
Set rowcount @cnt
Delete from t_name where id=@id and name=@name
and salary=@roll_no
Set rowcount 0
Fetch next from getall into @cnt,@id,@name,@roll_no
End
Close getall
Deallocate getall


Comments

No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: