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_id
column of thetitles
table to cause a deletion of matching rows in other tables. The trigger uses thetitle_id
column as a unique key to locate matching rows in thetitleauthor
,sales
, androysched
tables. - 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
discounts
table) to books (stored in thetitles
table) 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 |