Active database 75 76 trigger example triggers vs

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: activated and condition is true A trigger is a procedure that is trigger automatically invoked by the DBMS in response to specified changes to the database. 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, Title VARCHAR(50), Price DECIMAL(5,2), Authors VARCHAR(50), Pages INT, PubDate YEAR(4), Qty INT) ENGINE=InnoDB; ENGINE=InnoDB; CREATE TABLE Reorder (ISBN CHAR(10), ReorderDate DATE, 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

Ask a homework question - tutors are online