Chapitre 1 - Triggers
Chapitre 1 - Triggers
on Firebird RDBMS
Databases
See exercises
Triggers and transactions
The importants things to considerate are:
Triggers operate within the context of the transaction in the
program where they are fired. Triggers are considered part of the
calling program’s current unit of work.
If triggers are fired in a transaction, and the transaction is rolled
back, then any actions performed by the triggers are also rolled
back.
Exceptions
An exception is a named error message that can be raised
from a trigger or a stored procedure.
When raised in a trigger, an exception returns an error
message to the calling program and terminates the trigger,
unless the exception is handled by a WHEN statement in the
trigger.
Like procedures and triggers, exceptions are created and
stored in a database, where they can be used by any
procedure or trigger in the database. Exceptions must be
created and committed before they can be used in
triggers.
Exceptions (1/2)
An exception is a named error message that can be raised from
a trigger or a stored procedure.
When raised in a trigger, an exception returns an error message
to the calling program and terminates the trigger, unless the
exception is handled by a WHEN statement in the trigger.
Like procedures and triggers, exceptions are created and stored
in a database, where they can be used by any procedure or
trigger in the database. Exceptions must be created and
committed before they can be used in triggers.
To raise an existing exception in a trigger, use the following
syntax: EXCEPTION name;
Exceptions (2/2)
For example, suppose an exception is created as follows:
CREATE EXCEPTION RAISE_TOO_HIGH 'New salary exceeds old by more than 50%.;