Road Map to DB2 Programming

|
|
|
SQL Reference
| Describes SQL syntax, semantics, and the rules of the language.
Chapters 2 and 6 contains details about triggers.
|
Embedded SQL Programming Guide
| Explains how to develop applications that access DB2 databases using
embedded SQL. Chapter 8 contains details about triggers.
|
Administration Guide
| Contains information required to design, implement, and maintain a
database. Chapter 4 contains details about triggers.
|
|
|

|
|
|
|
|
| Embedded SQL
| DB2 CLI
|
|
trigsql
| X
|
| Demonstrates triggers and constraints.
|
|
|
|
|
A trigger defines a set of actions that are executed at, or
triggered by, a delete, insert or update operation on a specified table. When
such an SQL operation is executed, the trigger is said to be activated. The
trigger can be activated before the SQL operation or after it. You define a
trigger using the SQL statement CREATE TRIGGER.
You can use triggers that run before an update or insert in several
ways:
- To check or modify values before they are actually updated or inserted in
the database. This is useful if you need to transform data from the way the
user sees it to some internal database format.
- To run other non-database operations coded in user-defined functions.
Similarly, you can use triggers that run after an update or insert in
several ways:
- To update data in other tables. This is useful for maintaining
relationships between data or in keeping audit trail information.
- To check against other data in the table or in other tables. This is
useful to ensure data integrity when referential integrity constraints
aren't appropriate, or when table check constraints limit checking to the
current table only.
- To run non-database operations coded in user-defined functions. This is
useful when issuing alerts or to update information outside the database.
Figure 12. Inserts can activate a trigger
You gain several benefits using triggers:
- Faster application development
- Triggers are stored in the database, and are available to all
applications. This relieves you of the need to code equivalent functions for
each application.
- Global enforcement of business rules
- Triggers are defined once, and are used by all applications that use the
data governed by the triggers.
- Easier maintenance
- Any changes need to be made only once in the database instead of in every
application that uses a trigger.
[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]
[ DB2 List of Books |
Search the DB2 Books ]