If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Two triggers fired out with two actions and executing one SQL statement

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-11-04, 07:29
grofaty grofaty is offline
Registered User
 
Join Date: Jan 2003
Posts: 1,570
Two triggers fired out with two actions and executing one SQL statement

Hi,

I would like to write two triggers which are identical but are triggered with two actions. First one is triggered after insert action and secound one is after insert.

Can I write secound trigger with somekind of shortcut which is pointing to the SQL from the first trigger? Secound trigger uses the same SQL UPDATE statement (see sample bellow). I would like to have only one SQL statement and two triggers, to have the code of SQL in one place. Can this be done with triggers?

Sample - trigger 1:
create trigger db2admin.test_insert after insert on db2admin.test for each statement mode db2sql UPDATE ...

Sample - trigger 2:
create trigger db2admin.test_update after update of valueX on db2admin.test REFERENCING OLD AS o FOR EACH ROW mode db2sql UPDATE ...

Is it posible: create trigger db2admin.test_update after update .... run trigger db2adminl.test_insert?

My system:
DB2 v8 FP5 on Windows XP

Thanks,
Grofaty
Reply With Quote
  #2 (permalink)  
Old 05-11-04, 08:17
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
Grofaty,
According to the manual, no you cannot do that. This is what is allowed:
---------------------------------
SQL-procedure-statement
The SQL-procedure-statement can contain a dynamic compound statement or any of the SQL control statements listed in "Compound SQL (Dynamic)".

If the trigger is a BEFORE trigger, an SQL-procedure-statement can also include one of the following:

* a fullselect (A common-table-expression may precede a fullselect.)
* a SET variable statement.

If the trigger is an AFTER trigger or an INSTEAD OF trigger, an SQL-procedure-statement can also include one of the following:

* an INSERT SQL statement (not using nicknames)
* a searched UPDATE SQL statement (not using nicknames)
* a searched DELETE SQL statement (not using nicknames)
* 2a MERGE statement
* a SET variable statement
* a fullselect (A common-table-expression may precede a fullselect.)

The SQL-procedure-statement must not contain a statement that is not supported (SQLSTATE 42987).

The SQL-procedure-statement cannot reference an undefined transition variable (SQLSTATE 42703), a federated object (SQLSTATE 42997), or a declared temporary table (SQLSTATE 42995).

The SQL-procedure-statement in a BEFORE trigger cannot reference a materialized query table defined with REFRESH IMMEDIATE (SQLSTATE 42997).

The SQL-procedure-statement in a BEFORE trigger cannot reference a generated column, other than the identity column, in the new transition variable (SQLSTATE 42989).
-----------------------------

It would be nice to be able to do something like that from a code maintenance viewpoint. But alas, you will have to have the code in both triggers.

Andy
Reply With Quote
  #3 (permalink)  
Old 05-12-04, 10:07
grofaty grofaty is offline
Registered User
 
Join Date: Jan 2003
Posts: 1,570
ARWinner,

Thank you!

Grofaty
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On