Triggers
A trigger is a special kind of
Triggers are also useful for enforcing
Advantages of Using Triggers
Triggers are useful in these ways:
- Triggers are automatic: they are activated immediately after any modification to the table's data, such as a manual entry or an application action.
- Triggers can cascade changes through related tables in the database. For example, you can write a delete trigger on the
title_idcolumn of thetitlestable to cause a deletion of matching rows in other tables. The trigger uses thetitle_idcolumn as a unique key to locate matching rows in thetitleauthor,sales, androyschedtables. - Triggers can enforce restrictions that are more complex than those defined with check constraints. Unlike check constraints, triggers can reference columns in other tables. For example, a trigger can roll back updates that attempt to apply a discount (stored in the
discountstable) to books (stored in thetitlestable) with a price of less than $10.
For details about working with triggers, see the following topics:
| To | See |
|---|---|
| Create new triggers | Creating a Trigger |
| View existing triggers | Viewing a Trigger |
| Change the name of a trigger | Modifying and Renaming a Trigger |
| Delete stored triggers | Deleting a Trigger |