Release 10.1A: OpenEdge Development:
Progress 4GL Handbook

> ## Defining database triggers

> There are certain basic operations that you would always like to have occur when an application updates a record in a database table, regardless of where in a procedure the update occurs. In this way, you can be assured that code that acts as a validation check on an attempted update or a side effect of an update is executed consistently, without having to remember to add the code to every place in the application that changes that table. You can create special Progress 4GL procedures, called database trigger procedures, that contain this common code. You can register them in the Data Dictionary so that Progress knows to always run them when a corresponding database event occurs. They are also called schema trigger procedures because their names are registered in the database schema. It’s important to understand that the procedures themselves are not actually stored in the schema.

> For the most part, you should use these triggers for basic referential integrity checks to maintain the consistency and integrity of your application data. For example, the CustNum field in the Order table acts as a foreign key pointing to a Customer record with the same CustNum value that is the parent record for the Order. You would normally never want a user to save an Order (to the database) that didn’t have a valid Customer Number. Your application code itself should enforce this, but you might want to have a check at a lower level so that you can be certain it always executes.

> A trigger can also change other database records or other field values in the updated record as a side effect of a change. For example, you might want to delete all OrderLines for an Order if the user deletes the Order. Alternatively, you might want to check whether there are any outstanding OrderLines before allowing the user to delete the Order. Or you might want to calculate values for other fields, in the same table or in other tables, when one field value changes. The ExtendedPrice field that you saw updated in the OrderLine table is an example of this kind of trigger.

Copyright © 2005 Progress Software Corporation www.progress.com Voice: (781) 280-4000 Fax: (781) 280-4095