The Trigger Body

From InterBase
Jump to: navigation, search

Go Up to Creating Triggers


Everything following the AS keyword in the CREATE TRIGGER statement forms the procedure body. The body consists of an optional list of local variable declarations followed by a block of statements.

A block is composed of statements in the InterBase procedure and trigger language, bracketed by BEGIN and END. A block can itself include other blocks, so that there may be many levels of nesting.

InterBase procedure and trigger language includes all standard InterBase SQL statements except data definition and transaction statements, plus statements unique to procedure and trigger language.

Statements unique to InterBase procedure and trigger language include:

  • Assignment statements, to set values of local variables.
  • Control-flow statements, such as IFTHEN, WHILEDO, and FOR SELECTDO, to perform conditional or looping tasks.
  • EXECUTE PROCEDURE statements to invoke stored procedures.
  • Exception statements, to return error messages, and WHEN statements, to handle specific error conditions.
  • NEW and OLD context variables, to temporarily hold previous (old) column values and to insert or update (new) values.
  • Generators, to generate unique numeric values for use in expressions. Generators can be used in procedures and applications as well as triggers, but they are particularly useful in triggers for inserting unique column values. In read-only databases, generators can return their current value but cannot increment.
Note: All of these statements (except context variables) can be used in both triggers and stored procedures. For a full description of these statements, see Working with Stored Procedures.

Topics