Managing Triggers

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:

Creating Triggers

To create a trigger in Object Browser:

  1. On the Workspace home page, click SQL Workshop and then Object Browser.

    Object Browser appears.

  2. Click Create.

  3. From the list of object types, select Trigger.

  4. Select a table name and click Next.

  5. 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.

  6. Click Create Trigger.

Browsing a Trigger

To browse a trigger in Object Browser:

  1. On the Workspace home page, click SQL Workshop and then Object Browser.

    Object Browser appears.

  2. From the Object list, select Triggers.

  3. From the Object Selection pane, select a trigger.

    The Object Details view appears.

Summary of Available Views

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:

  • Compile

  • Download

  • Drop

  • Disable

Code

Displays the source code for the trigger. You can edit the code in this view. Actions you can perform in this view include:

  • Edit the code manually

  • Save & Compile

  • Find & Replace

  • Undo

  • Redo

  • Download Source

  • Drop

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.


Editing a Trigger

When you edit a trigger you can edit the code manually, perform a search and replace, and compile the trigger.

Editing a Trigger Manually

To edit a trigger manually:

  1. On the Workspace home page, click SQL Workshop and then Object Browser.

    Object Browser appears.

  2. From the Object list, select Triggers.

  3. From the Object Selection pane, select a trigger.

    The Code view appears. You can edit the code in this view.

  4. Click Find & Replace to perform a basic search and replace.

Compiling a Trigger

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:

  1. On the Workspace home page, click SQL Workshop and then Object Browser.

    Object Browser appears.

  2. From the Object list, select Triggers.

  3. From the Object Selection pane, select a trigger.

    The Details view appears.

  4. 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.

Downloading a Trigger

To save the current trigger as a file:

  1. On the Workspace home page, click SQL Workshop and then Object Browser.

    Object Browser appears.

  2. From the Object list, select Triggers.

  3. From the Object Selection pane, select a trigger.

    The Details view appears.

  4. Click Download Source to save the current trigger as a file.

  5. 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.

Dropping a Trigger

To save drop a trigger in Object Browser:

  1. On the Workspace home page, click SQL Workshop and then Object Browser.

    Object Browser appears.

  2. From the Object list, select Triggers.

  3. From the Object Selection pane, select a trigger.

    The Details view appears.

  4. Click Drop.

  5. To confirm, click Finish.