Documentation
 
 
 

CREATE TRIGGER

Name

CREATE TRIGGER -- define a new trigger

Synopsis

CREATE  OR REPLACE  TRIGGER name
{ BEFORE | AFTER } { INSERT | UPDATE | DELETE }  OR { INSERT | UPDATE | DELETE } ... ON
table
 FOR EACH ROW 
DECLARE
    declarations 
BEGIN
    statements
END;

Description

The CREATE TRIGGER command defines and names a trigger that will be stored in the database.

Parameters

name

The name to give to the trigger. This must be distinct from the name of any other trigger for the same table.

OR REPLACE

specify OR REPLACE to re-create the trigger if it already exists. Use this clause to change the definition of an existing trigger without first dropping it and re-creating it.

BEFORE
AFTER

determines whether the function is called before or after the event.

event

one of INSERT, UPDATE, or DELETE; this specifies the event that will fire the trigger. Multiple events can be specified using OR.

one or both of the remaining triggering event keywords may also be specified separated by the keyword, OR, in which case these are also defined as triggering events

table

the name of the table the trigger is for.

FOR EACH ROW

this specifies whether the trigger procedure should be fired once for every row affected by the trigger event, or just once per SQL statement. If neither is specified, the trigger is defined as a statement-level trigger.

declarations

declarations are variable, cursor, or type declarations

statements

statements are SPL program statements

Notes

The BEGIN - END block may contain an EXCEPTION.

Examples

Example 1: Section 15.6.1

Example 2: Section 15.6.2

Example 3: Section 15.6.3

Example 4: Section 15.6.4

See Also

DROP TRIGGER
 
 ©2004-2007 EnterpriseDB All Rights Reserved