Creating and editing database triggers
A database trigger fires when a triggering database modification occurs. For example, you can create a trigger to perform an action each time an insert takes place on the alerts.status table.
About this task
To create or edit a database trigger:
Procedure
- From the Netcool/OMNIbus Administrator window, select the Automation menu button.
- Click Triggers. The Triggers pane opens.
This pane lists all database, signal, and temporal triggers that are set up.
Tip: To view only one type of trigger, click Show Database Triggers Only, Show Temporal Triggers Only, or Show Signal Triggers Only in the toolbar. - To add a database trigger, click Add Database
Trigger in the toolbar. The Database Trigger Details window opens.
- To edit a database trigger, select the database trigger
to edit and then click Edit Trigger in the
toolbar. The Database Trigger Details window opens.
- Define or edit the trigger setup details as follows:
- Name
- Type a unique trigger name. If you are editing a trigger, you
cannot change the name. Tip: When you create ObjectServer objects, their names must begin with an uppercase or lowercase letter, followed by uppercase or lowercase letters, numbers, or underscore (_) characters, up to 40 characters in length. User, group, and role names can be any text string up to 64 characters in length and can include spaces. Names of ObjectServer objects are case-sensitive.
- Group
- Select the trigger group to which you want to assign the trigger.
- Add new trigger group
- Click this button if you want to create a new trigger group to which the trigger can then be assigned. The Trigger Group Details window opens. Complete this window and save your changes.
- When you return to the Database Trigger Details window, the new trigger group is shown as the currently-selected trigger group.
- Complete the Settings tab as follows:
- On
- Select the ObjectServer database and the database table that cause the trigger to fire.
- Priority
- Select a priority that determines the order in which the ObjectServer fires triggers when this database modification causes more than one trigger to fire. You can select numbers from 1 to 20, with 1 being the highest priority.
- Pre database action/Post database action
- Click Pre database action to indicate that the trigger action should run before the database modification that caused the trigger to fire occurs. Click Post database action to indicate that the trigger action should run after the database modification that caused the trigger to fire occurs.
- For example, you can click Pre database action to evaluate a user name before a row in the alerts.status table is deleted. In the trigger, you can detect whether the user is allowed to delete from the alerts.status table and, if not, prevent the database modification from taking place. If you click Post database action, the database modification always takes place.
- Delete/Insert/Reinsert/Update
- Use these options to specify the type of database modification that should occur.
- Row/Statement
- Click Row to set the trigger to fire once for each row that matches the trigger condition. Click Statement to set the trigger to fire once regardless of the number of matched rows in the table.
- Debug
- Select this check box to send debugging information to the ObjectServer message log each time the trigger fires.
- Enabled
- Select this check box to activate the trigger and make it available for use. Clear this check box to create the trigger without activating it at the present time, or to make the trigger unavailable. A disabled trigger does not fire when the associated database modification occurs.
- From the When tab, specify an optional WHEN clause that allows you to test for a particular condition before the action is performed. If the condition is not met, the action is not performed. You can use the helper buttons shown to the right of the field to construct the WHEN clause.
- From the Action tab, enter SQL commands
for the trigger.
The body of a trigger contains a set of SQL commands and programming constructs that manipulate data in the ObjectServer. The body of a trigger is enclosed within the keywords BEGIN and END. Each statement, except the last one, must be separated by a semi-colon (;).
You can optionally define (declare) local variables for use within a trigger. A local variable is a placeholder for values used during the execution of the trigger. Local variable declarations within a trigger must be separated by semi-colons (;).
The trigger body has the following syntax:[ DECLARE variable_declaration;...[;] ] BEGIN trigger_statement_list END;
You can use the SQL helper buttons shown to the right of the SQL editor panel to construct the SQL commands.
- From the Comment tab, enter an optional text comment for the trigger. This may be useful to anyone who is trying to understand how the trigger works.
- Save or cancel your changes as follows:
- OK
- Click this button to save the trigger details and close the window. New triggers are added to the Triggers pane.
- Cancel
- Click this button to close the window without saving your changes.