Define AlloyDB Triggers

AlloyDB supports table and view triggers. Use the table or view trigger editor to define a trigger.

To define a AlloyDB trigger

  1. In the Model Explorer, under Tables or views, right-click Triggers and click New.

    An instance of Trigger is created.

  2. Right-click the instance and click Properties.

    The AlloyDB Trigger Editor opens.

  3. In the navigation grid, select the trigger that you want to define and work with the following options:

    Click New New icon in property editors to create a new object on the toolbar to create a trigger. Use the Enter filter text box to filter a very large list of triggers to quickly locate the one that you want to define.

    Name

    Specifies the name of the view or table trigger. Change the name of the trigger in this field.

    Fire

    Specifies when the trigger function should be called.

    Generate

    Generates SQL during forward engineering. Clear the check box if you do not want to generate SQL.

  4. On the AlloyDB tab, work with the following options:
    Row Trigger

    Indicates that the trigger is a row trigger.

    Constraint Trigger

    Indicates that the trigger is a constraint trigger. The timing of trigger firing can be adjusted by setting constraints.

    Deferrable

    Indicates whether the constraint can be deferred.

    Initially Deferred

    Specifies the default time to check the constraint in case of a deferrable constraint. It is checked only at the end of the transaction.

    Function

    Specifies the function that is declared as taking no arguments and returning type trigger, which is executed when the trigger fires. Select a function from the drop-down list or click New New icon in property editors to create a new object to create one.

    Type

    Specifies the type of even on which the trigger will be fired.

    When

    Specifies the condition on which the trigger should execute.

    Column

    Specifies a list of columns. It indicates that the trigger will only fire if at least one of the listed columns is mentioned as a target of the UPDATE command.

  5. Work with the other tabs in the editor to access additional design features, for example:
    • Define the code type in the Code tab.
    • View expanded code in the Expanded tab.
  6. (Optional) Click the Comment tab and enter any comments that you want to associate with the object.
  7. (Optional) Click the UDP tab to work with user-defined properties for the object.
  8. (Optional) Click the Notes tab to view and edit user notes.
  9. Click Close.

    The trigger is defined and the AlloyDB Trigger Editor closes.

For more information on trigger properties, refer to AlloyDB documentation.