Murach’s Oracle SQL and PL/SQL, C16© 2014, Mike Murach & Associates, Inc.Slide 1 Thursday, March 12, 12:30 – 13:30PM. MIDTERM
Murach’s Oracle SQL and PL/SQL, C16© 2014, Mike Murach & Associates, Inc.Slide 2
Triggers A trigger is a statement that is executed automatically by the system as a side effect of a modification to the database. To design a trigger mechanism, we must: –Specify the conditions under which the trigger is to be executed. –Specify the actions to be taken when the trigger executes. Introduced to SQL standard in SQL:1999, Supported even earlier using non-standard syntax by most DBMSes. –Syntax illustrated here is for Oracle 11g.
Murach’s Oracle SQL and PL/SQL, C16© 2014, Mike Murach & Associates, Inc.Slide 4
Murach’s Oracle SQL and PL/SQL, C16© 2014, Mike Murach & Associates, Inc.Slide 5
Murach’s Oracle SQL and PL/SQL, C16© 2014, Mike Murach & Associates, Inc.Slide 6
Murach’s Oracle SQL and PL/SQL, C16© 2014, Mike Murach & Associates, Inc.Slide 7
Murach’s Oracle SQL and PL/SQL, C16© 2014, Mike Murach & Associates, Inc.Slide 8
Murach’s Oracle SQL and PL/SQL, C16© 2014, Mike Murach & Associates, Inc.Slide 9
Murach’s Oracle SQL and PL/SQL, C16© 2014, Mike Murach & Associates, Inc.Slide 10
Murach’s Oracle SQL and PL/SQL, C16© 2014, Mike Murach & Associates, Inc.Slide 11
Murach’s Oracle SQL and PL/SQL, C16© 2014, Mike Murach & Associates, Inc.Slide 12
Murach’s Oracle SQL and PL/SQL, C16© 2014, Mike Murach & Associates, Inc.Slide 13 Triggers are commonly used to monitor events occurring in a database. AFTER Triggers
Murach’s Oracle SQL and PL/SQL, C16© 2014, Mike Murach & Associates, Inc.Slide 14
Murach’s Oracle SQL and PL/SQL, C16© 2014, Mike Murach & Associates, Inc.Slide 15
Murach’s Oracle SQL and PL/SQL, C16© 2014, Mike Murach & Associates, Inc.Slide 16
Murach’s Oracle SQL and PL/SQL, C16© 2014, Mike Murach & Associates, Inc.Slide 17 Triggers for Views Recall updateable views?
Murach’s Oracle SQL and PL/SQL, C16© 2014, Mike Murach & Associates, Inc.Slide 18
Murach’s Oracle SQL and PL/SQL, C16© 2014, Mike Murach & Associates, Inc.Slide 19
Murach’s Oracle SQL and PL/SQL, C16© 2014, Mike Murach & Associates, Inc.Slide 20
Murach’s Oracle SQL and PL/SQL, C16© 2014, Mike Murach & Associates, Inc.Slide 21 Triggers on DDL Statements What’s a DDL statement?
Murach’s Oracle SQL and PL/SQL, C16© 2014, Mike Murach & Associates, Inc.Slide 22
Murach’s Oracle SQL and PL/SQL, C16© 2014, Mike Murach & Associates, Inc.Slide 23
Murach’s Oracle SQL and PL/SQL, C16© 2014, Mike Murach & Associates, Inc.Slide 24 Disable/Enable Triggers Why would I want to disable a trigger?
Murach’s Oracle SQL and PL/SQL, C16© 2014, Mike Murach & Associates, Inc.Slide 25
Murach’s Oracle SQL and PL/SQL, C16© 2014, Mike Murach & Associates, Inc.Slide 26
Murach’s Oracle SQL and PL/SQL, C16© 2014, Mike Murach & Associates, Inc.Slide 27 Compound Triggers Why do we need another type of trigger? It solves an well-known problem in Oracle. Contains code that executes: BEFORE the triggering statement executes. BEFORE the row is modified. AFTER the row is modified. AFTER the triggering statement has finished.
Murach’s Oracle SQL and PL/SQL, C16© 2014, Mike Murach & Associates, Inc.Slide 28
Murach’s Oracle SQL and PL/SQL, C16© 2014, Mike Murach & Associates, Inc.Slide 29
Murach’s Oracle SQL and PL/SQL, C16© 2014, Mike Murach & Associates, Inc.Slide 30
Murach’s Oracle SQL and PL/SQL, C16© 2014, Mike Murach & Associates, Inc.Slide 31
Murach’s Oracle SQL and PL/SQL, C16© 2014, Mike Murach & Associates, Inc.Slide 32
Murach’s Oracle SQL and PL/SQL, C16© 2014, Mike Murach & Associates, Inc.Slide 33
Murach’s Oracle SQL and PL/SQL, C16© 2014, Mike Murach & Associates, Inc.Slide 34
Murach’s Oracle SQL and PL/SQL, C16© 2014, Mike Murach & Associates, Inc.Slide 35
Murach’s Oracle SQL and PL/SQL, C16© 2014, Mike Murach & Associates, Inc.Slide 36
Murach’s Oracle SQL and PL/SQL, C16© 2014, Mike Murach & Associates, Inc.Slide 37
Murach’s Oracle SQL and PL/SQL, C16© 2014, Mike Murach & Associates, Inc.Slide 38