Schema and session database triggers
- Last Updated: March 30, 2020
- 2 minute read
- OpenEdge
- Version 12.2
- Documentation
ABL supports two types of database triggers: schema
and session. A schema trigger is a .p procedure
that you add, through the Data Dictionary, to the schema of a database.
Schema trigger code defined in the database is executed by database
clients.
A session trigger is a section of code that you add to a larger, enclosing procedure.
Schema triggers
You create schema triggers through the Table or Field Properties dialog box in the Data Dictionary. When you use the Data Dictionary to define a schema trigger for a table or field, the trigger is automatically added to the table or field’s data definitions. OpenEdge allows you to define the trigger while you are creating or modifying a table or field. This trigger definition is stored in a trigger procedure. For information on using the Data Dictionary to create and delete triggers, see Database Tools (Character only) and in graphical interfaces, the online help for the Data Dictionary. For more information on schema triggers, see Develop ABL Applications. For information on managing triggers online, see Optimize the OpenEdge Database for High Availability.
Differences between schema and session triggers
Although their syntax is slightly different, schema and session triggers provide similar functionality. The important difference between them is that schema triggers are independent procedures; whereas session triggers are contained within a larger procedure. Because of this difference, schema triggers always execute when a specified event occurs, regardless of what application initiates the event.
Session triggers are defined as part of a particular application and are only in effect for that particular application. Since session triggers are executed from within an enclosing procedure, they have access to the frames, widgets, and variables defined in the enclosing procedure.
Since schema triggers are compiled separately from the procedure that initiates their execution, they do not have access to the procedure’s frames, widgets, and variables. Use schema triggers for processing that you always want to perform for a specific event. For example, when an order record is deleted, you might always want to delete the corresponding order-line records.
Use
session triggers to perform additional or independent processing
when the event occurs. Both types of trigger scan return ERRORS that
cause the associated event to fail. For more information on the ERROR option
of the RETURN statement, see ABL Reference.
Trigger interaction
You can define a schema and a session trigger for the same table/event or field/event pair. How the triggers interact depends on how you define them.
Ordinarily, both triggers
execute, with the session trigger executing first (except for the FIND session
trigger, which executes after the FIND schema trigger).
In this way, the schema trigger always has precedence over the session
trigger. For a WRITE, DELETE, CREATE,
or ASSIGN event, the schema trigger can override
the session trigger. For a FIND event, the schema
trigger can preempt the session trigger.