July 18, 2009 at 2:10 am
Hi
I have created a trigger for all insert,update and delete actions like this
Create trigger tg_name on tb_name
after insert,update and delete
as
.
.
.
How I can recognize that which action has fired the trigger?
Thanks
July 18, 2009 at 3:58 am
Hi,
For this you need to make assumptions as:
IF EXISTS(SELECT * FROM INSERTED)
AND NOT EXISTS(SELECT * FROM DELETED) BEGIN
-- this is an insert trigger
END
IF EXISTS(SELECT * FROM INSERTED)
AND EXISTS(SELECT * FROM DELETED) BEGIN
-- this is an update trigger
END
IF NOT EXISTS(SELECT * FROM INSERTED)
AND EXISTS(SELECT * FROM DELETED) BEGIN
-- this is a delete trigger
END
Let me know if it helps you.
Thanks,
Tejas Shah
July 18, 2009 at 5:58 am
you can also have a flag field on the target table with a default value of 0 and update it to 1 from within your trigger statements.
this way u'll be able to identify by query the table for all rows that were modified by the trigger operation.
July 18, 2009 at 9:55 pm
Dera Tejas Shah
Thank you for your reply,Your solution is very good and practical.This is exactly what I need
With many thanks to other replies
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply