Create a trigger

更新时间:
复制 MD 格式

In OceanBase Developer Center (ODC), open a connection. In the navigation pane on the left, click the Triggers tab to view the trigger list. In the upper-right corner of the trigger list, click + to create a trigger. You can also click New in the top navigation bar to create an object.

To create a trigger, follow these three steps:

  1. Specify basic information.

  2. Configure advanced settings.

  3. Confirm the SQL statement.

Specify basic information

The first step is to specify the basic information for the trigger. The Basic Information tab contains the following fields:

  • Trigger name: Specify a name for the trigger.

  • Base object schema: The schema where the base object resides.

  • Base object type: The type of the base object. Currently, only the TABLE object type is supported.

  • Base object name: The name of the base object.

  • Trigger status: Set the trigger status to Enable or Disable.

Configure advanced settings

The second step is to configure advanced settings on the Advanced Settings tab. This tab contains the following fields:

  • Trigger type: Select the trigger type. Currently, only SIMPLE triggers are supported.

  • Trigger timing: Specify when the trigger fires. The options are BEFORE or AFTER the triggering event.

  • Level: Specify the trigger level. Currently, only row-level triggers are supported.

  • Event: Specify the operation that fires the trigger. You can select INSERT, UPDATE, or DELETE events.

  • Column (Optional): The columns to which the Event applies. This option is displayed when you select SELECT for the Event. In this case, you must select one or more columns because the current version supports only row-level triggers on table objects.

  • Reference old value (Optional): Specify an alias for the referenced object. This corresponds to the REFERENCING OLD clause in the trigger creation syntax.

  • Reference new value (Optional): Specify an alias for the referenced object. This corresponds to the REFERENCING NEW clause in the trigger creation syntax.

  • Clause condition (Optional): Specify a logical expression. The trigger body is executed only if this expression evaluates to True.

Confirm the SQL statement

After you complete the Basic Information and Advanced Settings tabs, click Next: Confirm SQL to open the statement editing page.

On the statement editing page, a trigger definition statement is generated based on the information from the previous tabs. You must complete the statement by adding the trigger body, which defines the operations to be executed when the trigger fires. After you complete the trigger body, click Create in the upper-right corner to create the trigger.

The toolbar on the editing page provides the following functions:

Feature

Description

Format

Click this button to format the selected SQL statements or all SQL statements in the current SQL window. Formatting includes operations such as indenting, adding line breaks, and highlighting keywords.

Find/Replace

Enter content in the find box to search the script. After finding the content, you can enter new content in the replace box to replace it.

Undo

Revert the script to the state before the last operation.

Redo

After an Undo operation, re-apply the operation that was undone.

Case

Provides three options: ALL UPPERCASE, all lowercase, and Capitalize. Converts the selected text in your script to the corresponding format.

Indent

Provides two options: Add Indent and Remove Indent. Adds or removes indents for the selected statements in your script.

Comment

Provides two options: Add Comment and Remove Comment. Converts the selected statements in your script into comments or back into SQL statements.

Previous

Return to the Create Trigger page. You can continue to edit or modify the values on the Basic Information and Advanced Settings tabs.