|
|
CREATE TRIGGER
Creates a trigger which is invoked by data changes in a named table or view.
Usage
Embedded/Interactive/ODBC/JDBC.
Description
A trigger is created on a table or view (table reference).
For a complete description of triggers, see the Mimer SQL Programmer's Manual, Triggers.
The
trigger-nameshould follow the normal rules for naming database objects, see Naming Objects.If
trigger-nameis specified in its unqualified form, the trigger will be created in the schema which has the same name as the current ident.If
trigger-nameis specified in its fully qualified form (i.e.schema-name.trigger-name) the trigger will be created in the named schema (in this case, the current ident must be the creator of the specified schema).The
trigger-actionwill be executed when the data manipulation operation specified bytrigger-eventoccurs ontable-referenceand anysearch-conditionspecified in theWHENclause of thetrigger-actionevaluates to true.If the trigger time is
AFTER, the trigger will be invoked after the data manipulation operation specified bytrigger-eventhas been performed ontable-reference.If the trigger time is
BEFORE, the trigger will be invoked before the data manipulation operation specified bytrigger-eventhas been performed ontable-reference.If the trigger time is
INSTEAD OF, the trigger will be executed in place of the data manipulation operation specified bytrigger-event, i.e. the data manipulation statement invoking the trigger will not actually change any data intable-reference. In this case the only data changes possible are those performed by thetrigger-action.In the
alias-list,OLD TABLEandNEW TABLEare used to create two special temporary tables showing those rows oftable-referenceselected by the data manipulation statement invoking the trigger.The temporary table created by using
OLD TABLEshows the affected rows as they were before the data manipulation statement was executed.The temporary table created by using
NEW TABLEshows the affected rows in a state consistent with the data manipulation statement having been executed. In the case of anAFTERtrigger, the same rows can be found intable-referencebut for anINSTEAD OFtrigger, the matching rows oftable-referencewill actually appear as they do in theOLD TABLEalias because the data manipulation statement is not actually executed.Restrictions
The trigger and
table-referencemust belong to the same schema.Two triggers with the same name cannot belong to the same schema.
If the trigger time is
INSTEAD OF, thentable-referencemust be the name of a view.
OLD TABLEandNEW TABLEmay each be specified only once in thealias-listand the sametable-alias-namemust not appear twice in the same list.
OLD TABLEmay not be specified if thetrigger-eventisINSERT.
NEW TABLEmay not be specified if thetrigger-eventisDELETE.If the trigger time is
BEFORE, theREFERENCINGkeyword andalias-listmust not be specified.If the
procedural-sql-statementof thetrigger-actionis aCOMPOUND STATEMENT, it must beATOMIC.The creator of the trigger must hold the appropriate access rights, with grant option, for all operations performed in the trigger action.
The
trigger-actionmust not contain aCOMMITorROLLBACKstatement.If the trigger time is
BEFORE, the following restrictions apply to thetrigger-action:
- the
trigger-actionmust not contain any SQL statement that performs an update (i.e.DELETE,INSERTandUPDATEstatements are not permitted)- a routine whose access clause is
MODIFIES SQL DATAmust not be invoked from within thetrigger-action.A trigger can be created on tables that have columns defined as LARGE OBJECT data type, with the restriction that it is not possible to refer to such columns in the new table in an instead of trigger.
Notes
The
trigger-actionis always executed in the transaction started for the data manipulation operation which caused the trigger to be invoked. Thus, if the data manipulation operation is subject to a rollback, all operations performed in thetrigger-actionwill also be undone and an unhandled error occurring in thetrigger-actionwill be treated like an error in the triggering data manipulation statement.During the execution of the
trigger-action, the effect of changes made in the transaction are visible.The scope of the
trigger-actionis the optionalWHENclause and theprocedural-sql-statement.The tables specified by using
OLD TABLEandNEW TABLEin thealias-listare temporary and are local to scope of thetrigger-action. It is not possible to perform any data change operations on either table and the data contained in each will not otherwise change during the time it exists.Data manipulation operations performed in the
trigger-actionmay cause the trigger to be invoked recursively. Trigger execution in a recursive situation will proceed normally in every respect.If the body of the trigger contains operations on tables located in a databank with work option, these operations will not be part of the atomic statement that constitute the trigger execution.
Example
CREATE TRIGGER mimer_store_book.titles_after_insert AFTER INSERT ON mimer_store_book.titles REFERENCING NEW TABLE AS btl BEGIN ATOMIC ... ... END -- of trigger mimer_store_book.titles_after_insertFor more information, see the Mimer SQL Programmer's Manual, Triggers.
Standard Compliance
|
Mimer Information Technology AB Voice: +46 18 780 92 00 Fax: +46 18 780 92 40 info@mimer.se |
|
|