Re: How to distinguish operation type in trigger?
- From: Hubert Trzewik <hubert.trzewik@xxxxxxxxx>
- Date: 31 May 2007 06:32:09 -0700
On May 31, 1:48 pm, M A Srinivas <masri...@xxxxxxxxx> wrote:
On May 31, 3:19 pm, Hubert Trzewik <hubert.trze...@xxxxxxxxx> wrote:
Hi,
I want to have all-in-one trigger, defined like this:
CREATE TRIGGER MyInsertDeleteUpdateHandler
ON MyTable
FOR DELETE, INSERT, UPDATE
AS
BEGIN
(...)
END
Now, how can I tell why this trigger was fired (what event caused
trigger to be fired) - was it DELETE, INSERT or UPDATE?
Is there something like this: @@event_type,
so I could do for example IF (@@event_type = DELETE) (...)
Of course I can create 3 triggers instead of 1, to be sure what event
fired my trigger.
I can also count records in _deleted_, _inserted_ tables or to do
JOINs with it. But, _inserted_ table is common for UPDATE and INSERT
events..
Any suggestions?
Thanks in advance.
Hubert
For Inserted : Rows are in inserted only
For Updated: Rows are in inserted and deleted
For deleted: Rows are in deleted only
That's right. One test more and.. UPDATE is seen both in _inserted_
and _deleted_, so I can distinguish it from INSERT (and DELETE of
course).
Thanks a lot.
Hubert
.
- References:
- How to distinguish operation type in trigger?
- From: Hubert Trzewik
- Re: How to distinguish operation type in trigger?
- From: M A Srinivas
- How to distinguish operation type in trigger?
- Prev by Date: Re: How to distinguish operation type in trigger?
- Next by Date: Re: needed: 1 + null = 1 (Correction)
- Previous by thread: Re: How to distinguish operation type in trigger?
- Index(es):