This section describes database sequences in CREATE triggers.

To see one of the basic uses for triggers, look at an example trigger procedure:

  1. Cancel out of the Table Triggers and Table Properties dialog boxes. In Data Dictionary, select the Order table and click the Table Properties button.
  2. Click the Triggers button. The Table Triggers dialog box appears:

    To assign each Order a unique number, the procedure uses a Database Sequence that stores the latest value assigned to an Order.

  3. Define sequences in the Data Dictionary by clicking the Sequences button in the Data Dictionary main window:
The online help tells you more about how to create sequences in your own database. Basically, each sequence is an Integer value maintained for you in the database. When you define it, you simply give the sequence a name, a starting value, a maximum value, and a value to increment by. Then, each time the AVM encounters the NEXT-VALUE function in your application, it increments the sequence and returns the new value, as in the example from this trigger:
ASSIGN order.ordernum = NEXT-VALUE(NextOrdNum)
You can also use the 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:
CURRENT-VALUE ( sequence-name ) = integer-expression.

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.

You can also use a 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:
order.orderdate = TODAY
order.promisedate = TODAY + 14