IBM Books

Road Map to DB2 Programming


Triggers



* Figure crosref not displayed.



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.




* Figure programs not displayed.






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:

Similarly, you can use triggers that run after an update or insert in several ways:

Figure 12. Inserts can activate a trigger


* Figure sqlu0trg not displayed.

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 ]