This preview shows page 1. Sign up to view the full content.
Unformatted text preview: activated and condition is true A trigger is a procedure that is
automatically invoked by the DBMS in
response to specified changes to the
active database 75 76 Trigger Example Triggers vs. Constraints CREATE TABLE Books Similarity: associated with an event
Constraint - action occurs when changes to d.b.
violate constraint condition
Trigger - action occurs when trigger condition
is satisfied (ISBN
CHAR(10) PRIMARY KEY,
ENGINE=InnoDB; CREATE TABLE Reorder (ISBN
ReorderQty INT); Difference: Constraints are restricted to ensuring
condition not violated; triggers can be used to
execute arbitrary actions.
77 78 Trigger Example (continued) Trigger Example (continued)
Revised trigger: Almost correct trigger to insert row in Reorder when quantity of book in stock
drops below 5: CREATE TRIGGER ReorderTrigger
AFTER UPDATE ON Books
REFERENCES NEW ROW AS NewRow,...
View Full Document
- Fall '12