Procedure documentationCreating Database Triggers Locate this document in the navigation structure

 

A database trigger is a special database procedure (sequence of statements) that the system executes after an SQL statement changes data in a table (or a view table based on this table).

Prerequisites

  • You are logged on to the database as a database user.

  • You are the owner of the table for which you want to create the database trigger.

  • You are authorized to perform the actions defined within the trigger.

  • The database is in the ONLINE operational state.

Procedure

  1. Open the SQL editor.

    More information: Entering and Executing SQL Statements

  2. To create the database trigger, create the CREATE TRIGGER statement.

    More information: SQL Reference Manual, CREATE TRIGGER Statement (create_system_trigger_statement)

Result

The database trigger is displayed in the Explorer (as read-only) in the Triggers directory.

Example

If you change a hotel number in the hotel table, the following database trigger ensures that the system also changes the hotel number in the room table.

CREATE TRIGGER hotel_update FOR hotel.hotel AFTER UPDATE EXECUTE

(TRY

IF NEW.hno <> OLD.hno

THEN UPDATE hotel.room SET hno = :NEW.hno WHERE hno = :OLD.hno;

CATCH

IF $rc <> 100

THEN STOP ($rc, 'unexpected error');)

More Information

SQL Tutorial, Database Triggers