![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
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.. |
|
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 |
#3
| |||
| |||
|
|
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 |
#4
| |||
| |||
|
|
On May 31, 3:19 pm, Hubert Trzewik <hubert.trze... (AT) gmail (DOT) com> 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 |
#5
| |||
| |||
|
|
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 |
#6
| |||
| |||
|
|
Why not just break up the action into three triggers? if there is common code use a stored procedure got that part. |
![]() |
| Thread Tools | |
| Display Modes | |
| |