A database trigger is a stored subprogram associated with a database table, view, or event. The trigger can be called once, for example when an event occurs, or many times, for example for each row affected by an INSERT, UPDATE, or DELETE statement.
Topics:
To create a trigger in Object Browser:
On the Workspace home page, click SQL Workshop and then Object Browser.
Object Browser appears.
Click Create.
From the list of object types, select Trigger.
Select a table name and click Next.
Select the appropriate trigger attributes, enter the trigger body, and click Next.
A confirmation page appears, which displays the SQL used to create the trigger.
Click Create Trigger.
To browse a trigger in Object Browser:
On the Workspace home page, click SQL Workshop and then Object Browser.
Object Browser appears.
From the Object list, select Triggers.
From the Object Selection pane, select a trigger.
The Object Details view appears.
Click the tabs at the top of the page to view different reports about the trigger. Table 1-10 describes all available views.
Table 1-10 Available Views for Triggers
View | Description |
---|---|
Object Details |
(Default) Lists of the details about the current trigger. Actions you can perform include:
|
Code |
Displays the source code for the trigger. You can edit the code in this view. Actions you can perform in this view include:
See Also: "Editing a Trigger", "Compiling a Trigger", "Downloading a Trigger", and "Dropping a Trigger" |
Errors |
Displays errors related to the current trigger. |
SQL |
Displays the SQL necessary to re-create the trigger. |
When you edit a trigger you can edit the code manually, perform a search and replace, and compile the trigger.
To edit a trigger manually:
On the Workspace home page, click SQL Workshop and then Object Browser.
Object Browser appears.
From the Object list, select Triggers.
From the Object Selection pane, select a trigger.
The Code view appears. You can edit the code in this view.
Click Find & Replace to perform a basic search and replace.
If you edit and make changes to a function, you must compile to save your changes. There is no save function because this is just a view of the object within the database. Compiling re-creates the object in the database.
To compile a trigger in Object Browser:
On the Workspace home page, click SQL Workshop and then Object Browser.
Object Browser appears.
From the Object list, select Triggers.
From the Object Selection pane, select a trigger.
The Details view appears.
To compile the current trigger:
Under Object Details, click Compile.
Under Code, click Save & Compile.
If the compilation fails, an error message displays above the code.
To save the current trigger as a file:
On the Workspace home page, click SQL Workshop and then Object Browser.
Object Browser appears.
From the Object list, select Triggers.
From the Object Selection pane, select a trigger.
The Details view appears.
Click Download Source to save the current trigger as a file.
To download the current tripper:
Under Object Details, click Download.
Under Code, click Download Source.
If the compilation fails, an error message displays above the code.
To save drop a trigger in Object Browser:
On the Workspace home page, click SQL Workshop and then Object Browser.
Object Browser appears.
From the Object list, select Triggers.
From the Object Selection pane, select a trigger.
The Details view appears.
Click Drop.
To confirm, click Finish.