Use database sequences in CREATE triggers
- Last Updated: January 16, 2024
- 2 minute read
- OpenEdge
- Version 12.8
- Documentation
This section describes database sequences in CREATE triggers.
To see one of the basic uses for triggers, look at an example trigger procedure:
- Cancel out of the Table Triggers and Table
Properties dialog boxes. In Data Dictionary,
select the
Ordertable and click the Table Properties button. - Click the Triggers button. The Table
Triggers dialog box appears:
To assign each
Ordera unique number, the procedure uses a Database Sequence that stores the latest value assigned to anOrder. - Define sequences in the Data Dictionary by clicking the
Sequences button in the Data
Dictionary main window:
NEXT-VALUE function in your application, it increments the sequence
and returns the new value, as in the example from this trigger:
|
CURRENT-VALUE function to access the current
sequence value without incrementing it. Also, there is a CURRENT-VALUE
statement that allows you to assign a new value to the sequence:
|
You should use the CURRENT-VALUE statement only to reset a sequence in a
database that is not being actively used. You should never put such a statement in your
application code to assign individual sequence values, as this is not reliable in a
multi-user environment.
Both NEXT-VALUE and CURRENT-VALUE allow you to specify
a logical database name as an optional second argument if the sequence name might not be
unique among all your connected databases.
Assigning a unique Integer key to a new record is the most common use of
CREATE triggers.
CREATE trigger to assign other initial values that need to
be expressions that can not be represented in the Data Dictionary
when you define fields. This trigger assigns the value of the built-in function
TODAY to the OrderDate, and TODAY +
14 as the default PromiseDate:
|