Neoview Database Administrator's Guide (R2.3)
Triggers
A trigger is a mechanism that resides in the database and specifies that when a particular
action—an insert, delete, or update—occurs on a table, DB Admin should automatically perform
one or more additional actions.
About Triggers
Create triggers by providing the following parameters:
• A name for the trigger
• BEFORE or AFTER (a named event)
• The event
• ROW or STATEMENT granularity
• Alias names
• Statement that activates the trigger
• A condition that activates the trigger
Triggers are executed in this order:
1. BEFORE triggered statement
2. Triggering statement
3. Referential actions
4. AFTER triggered statement
Triggers are not supported for statements that reference rowsets.
To create a trigger:
In this example, suppose we have a database to record prescriptions. There are two tables:
prescriptions lists prescriptions for each patient, and generic_drugs lists generic
equivalents for brand name drugs. We will add a trigger on prescriptions so that before a
prescription record is inserted, this trigger looks up the drug in generic_drugs . If it finds
the prescribed drug, a generic drug is substituted and the trigger updates the instructions in the
prescription record to indicate this.
Creating Triggers on Tables
1. Start DB Admin and log on using the user ID that created the table or log on as a user
authorized to grant privileges to others on that table.
2. Click the Database tab, then navigate to the schema and table where you want to create a
trigger.
3. Right-click the table for which you want to create a trigger and select Create Trigger to start
the Create Trigger Wizard.
4. Enter a name for the trigger and then click Next:
Triggers 63