Managing Triggers

A database trigger is a stored subprogram associated with a database table, view, or event. You can create, browse, edit, compile, download, drop, disable or enable a trigger and view report.

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.

Creating Triggers

Create a trigger using Object Browser.

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 the Create icon.
  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

Select a trigger from the Object Selection pane and view different reports about the 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.

  4. Click the tabs at the top of the page to view different reports about the trigger.

See Also:

"Reports for Triggers"

Reports for Triggers

Alternative views available when viewing a trigger in Object Browser.

Table 2-10 describes all available reports for triggers.

Table 2-10 Available Reports 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

  • Auto Complete

  • Undo

  • Redo

  • Download Source

  • Drop

Errors

Displays errors related to the current trigger.

SQL

Displays the SQL necessary to re-create the trigger.

Editing a Trigger Manually

Select a trigger from the Object Selection pane and click Code.

  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.

  4. Click Code tab.
  5. You can edit the code in this view. Other edit controls include:
    • Find

    • Replace

    • Auto Complete

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

Compiling a Trigger

Select a trigger from the Object Selection pane and click Save & Compile.

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

Select a trigger from the Object Selection pane and click Download Source to save the current trigger as a file.

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 trigger:
    • Under Object Details, click Download.

    • Under Code, click Download Source.

    If the compilation fails, an error message displays above the code.

Dropping a Trigger

Select a trigger from the Object Selection pane and click Drop.

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

Disabling and Enabling a Trigger

Select a trigger from the Object Selection pane and click Disable or Enable.

To disable and enable 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 Disable.

    Note:

    The Enable button is activated. If you want to enable the trigger, click Enable.