Creating a Trigger

To create a trigger from Cview, do one of the following:

The Trigger panel displays on the right side.

Use the tabs in the Trigger panel to build a trigger definition.

Triggers Tab

  1. In the Name field, type a name for the trigger.
  2. In the Schema field, choose a schema. This value can be any schema except for SYS.
  3. In the Event field, choose the action for the trigger:
  4. In the Firing Time field, choose whether the trigger should fire BEFORE or AFTER the event.
  5. In the Table field, choose the table on which the trigger should act.
  6. In the Trigger Action field, specify the statement that the firing trigger will execute. The trigger action can be any valid SQL-J statement, including one with Java method calls. For example:

    UPDATE CustomizedTours SET getTotalCost =
    customized_tour::getTotalCost()

    NOTE: The trigger action can reference database objects in tables other than that specified in step 5. However, if any of these database objects is dropped, the trigger is invalidated.

    NOTE: There are restrictions on a trigger action, for example it may not contain dynamic parameters or modify or drop the table on which the trigger is defined. For a complete list of restrictions, see the Cloudscape Developer's Guide.

Options Tab

On the Options tab, optionally specify referencing information for the trigger. Typically, you specify referencing information when the trigger action refers to data that is currently being changed by the database event that fired the trigger. The trigger may need to refer to the old (pre-change, or "before") values or the new (post-change or "after") values.

  1. If the qualifying event is an UPDATE clause, the top of the Options tab displays a list of the columns in the affected table. Select which columns should fire the trigger when updated. (To multi-select hold down the Shift key while clicking or arrowing)
  2. Optionally, in the Referencing field specify an OLD or NEW transition variable. This value is used when a trigger action must reference the table or row affected by the qualifying event. Specify OLD to refer to table or row values prior to the change, or NEW to refer to the table or row values after the change.

    NOTE: INSERT row or table triggers cannot reference an OLD row or table. DELETE row or table triggers cannot reference a NEW row or table.

    NOTE: Steps 3 through 5 only apply if you specify a value for this field.

  3. In the Reference Type field, choose whether you are referencing an old or new ROW or TABLE.
  4. In the Reference As field, optionally specify an alias or correlation name for the NEW or OLD transition variable. You can specify your own alias, or keep the default identifier AREFERENCE.

    Specify a value for Reference As if you do not want to use the default variable names OLD or NEW. For example, if a DELETE operation fires a row trigger that references OLD values, you could specify the alias DELETEDROW for use in place of `OLD'. You could then use DELETEDROW in the trigger action statement.

  5. In the For Each field, choose whether this is a Row trigger or a Statement trigger.
  6. At the bottom of the Options tab, toggle the state of the Enable Trigger checkbox to enable or disable the trigger. By default, the trigger is enabled.

SQL Tab

The SQL tab displays the trigger creation text, as well as a statement for enabling or disabling the trigger, and the statement for dropping the trigger.