한국어 Login Register

Versions available for this page: CUBRID 8.3.0  |  CUBRID 8.3.1  |  CUBRID 8.4.0 |  CUBRID 8.4.1  | 

TRIGGER Condition

Description

You can specify whether a trigger action is to be performed by defining a condition when defining the trigger.

  • If a trigger condition is specified, it can be written as an independent compound expression that evaluates to true or false. In this case, the expression can contain arithmetic and logical operators allowed in the WHERE clause of the SELECT statement. The trigger action is performed if the condition is true; if it is false, action is ignored.
  • If a trigger condition is omitted, the trigger becomes an unconditional trigger, which refers to that the trigger action is performed whenever it is called.
Example 1

The following is an example of using a correlation name in an expression within a condition. If the event type is INSERT, UPDATE or DELETE, the expression in the condition can reference the correlation names obj, new or old to access a specific column. This example prefixes obj to the column name in the trigger condition to show that the example trigger tests the condition based on the current value of the record column.

CREATE TRIGGER example

........

IF obj.record * 1.20  < 500

.......     

Example 2

The following is an example of using the SELECT statement in an expression within a condition. The trigger in this example uses the SELECT statement that contains an aggregate function COUNT( * ) to compare the value with a constant. The SELECT statement must be enclosed in parentheses and must be placed at the end of the expression.

CREATE TRIGGER example

......

IF 1000 >  (SELECT COUNT( * ) FROM participant)

......

Caution

The expression given in the trigger condition may cause side effects on the database if a method is called while the condition is performed. A trigger condition must be constructed to avoid unexpected side effects in the database.