|
|
Trigger Time
The trigger time specifies when, in relation to the execution of the triggering data manipulation statement, the trigger is executed.
The possible values for the trigger time for a base table are:
- BEFORE
This specifies that the trigger will be executed prior to the execution of the triggering data manipulation statement. The table name must specify a base table which is located in a databank with TRANS or LOG option.
- AFTER
This specifies that the trigger will be executed following the execution of the triggering data manipulation statement.
It is possible to have both row and statement triggers for the same event on a base table. The logic for invoking statement and row triggers for a base table can schematically be seen as:
-- -- invoke before statement triggers -- call before_statement_trigger_1; ... call before_statement_trigger_n; get_data: loop -- -- get rows affected by data manipulation statement -- if not found then leave get_data; end if; -- -- invoke before row triggers -- call before_row_trigger_1; ... call before_row_trigger_n; -- -- save data to old/new table if used -- -- -- do actual operation -- delete/insert/update; -- -- invoke after row triggers (currently not supported) -- call after_row_trigger_1; ... call after_row_trigger_n; end loop; -- -- invoke after statement triggers -- call after_statement_trigger_1; ... call after_statement_trigger_n;Note that this schema includes after row trigger even though these are not supported in this version of Mimer SQL.
- INSTEAD OF
For a view it is possible to create instead of triggers. This specifies that the trigger will execute when the triggering data manipulation statement would normally be executed. In this case the triggering data manipulation statement itself has no direct effect, it only causes the trigger to execute.
Analogously with base tables, if you have both statement and row trigger the schematical code for invoking triggers would look like
get_data: loop -- -- get rows affected by data manipulation statement -- if not found then leave get_data; end if; -- -- execute instead of row trigger -- call instead_of_row_trigger_1; ... call instead_of_row_trigger_n; -- -- save data to old/new table if used -- end loop; -- -- call instead of statement triggers -- call instead_of_statement_trigger_1; ... call instead_of_statement_trigger_n;Note that this schema include instead of row trigger even though these are not supported in this version.
Example:
Example of an instead of trigger, which can be used for handling join views.
CREATE TRIGGER book_details_instead_of_update INSTEAD OF UPDATE ON mimer_store_book.book_details REFERENCING NEW TABLE AS new_bd BEGIN ATOMIC -- -- Update one table with some of the data from the join view -- UPDATE titles SET authors_list = (SELECT authors_list FROM new_bd WHERE item_id = titles.item_id) WHERE item_id IN (SELECT item_id FROM new_bd); -- -- Update another table using another column from the join view -- UPDATE producers SET producer_name = (SELECT publisher FROM new_bd WHERE item_id = producers.producer_id) WHERE producer_id IN (SELECT item_id FROM new_bd); END
|
Mimer Information Technology AB Voice: +46 18 780 92 00 Fax: +46 18 780 92 40 info@mimer.se |
|
|