Lecture 7. Triggers
Lecture 7. Triggers
UNIT IV 1
General Introduction
• There are several different ways to protect a database from
corruption:
• Datatypes for the individual columns
• Primary key and other uniqueness constraints
• Referential integrity constraints:
• Implement relationships between tables
• Ensure that enumerated values are valid
• Implementing reference data
• Database code that implements complex (non declarative) constraints
• One major benefit to doing all of this in the database is that there
is no way to “back door” the database.
• The other benefit is that the stored procedure/function/trigger runs
on the server, which saves on network traffic.
Triggers: Motivation
• Assertions are powerful, but the DBMS often can’t tell
when they need to be checked.
• Attribute- and tuple-based CHECKs are checked at known
times, but are not powerful.
• Triggers let the user decide when to check for any
condition.
Event-Condition-Action
Rules
• Another name for “trigger” is ECA rule, or event-condition-
action rule.