Triggers Notes

download Triggers Notes

of 2

Transcript of Triggers Notes

  • 8/12/2019 Triggers Notes

    1/2

    Row Level Triggers

    Row level triggers execute once for each row in a transaction. The commands of row

    level triggers are executed on all rows that are affected by the command that enables

    the trigger.

    For example, if an UPDT! statement updates multiple rows of a table, a row trigger is

    fired once for each row affected by the UPDT! statement. "f the triggering statementaffects no rows, the trigger is not executed at all. Row level triggers are created using

    the F#R !$% R#& clause in the $R!T! TR"''!R command.

    Statement Level Triggers(tatement level triggers are triggered only once for each transaction. For example whenan UPDT! command update )* rows,the commands contained in the trigger are executed only once, and not with everyprocessed row. (tatement level trigger are the default types of trigger created via the$R!T! TR"''!R command.

    Before Trigger(ince triggers are executed by events, they may be set to occur immediately before orafter those events. &hen a trigger is defined,you can specify whether the trigger must occur before or after the triggering event i.e."+(!RT, UPDT!, or D!!T! commands.-!F#R! trigger execute the trigger action before the triggering statement. These typesof triggers are commonly used in the following situation-!F#R! triggers are used when the trigger action should determine whether or not thetriggering statement should be allowed to complete.-y using a -!F#R! trigger, you can eliminate unnecessary processing of the triggeringstatement. For example To prevent deletion on (unday,

    for this we have to use (tatement level before trigger on D!!T! statement.-!F#R! triggers are used to derive specific column values before completing atriggering "+(!RT or UPDT! statement.

    After TriggerFT!R trigger executes the trigger action after the triggering statement is executed.FT!R triggers are used when you want the triggering statement to complete beforeexecuting the trigger action.For example To perform cascade delete operation, it means that user delete the recordfro one table,but the corresponding records in other tables are delete automatically by a trigger which

    fired after the execution of delete statement issued by the user.&hen combining the different types of triggering actions, there are mainly )/ possiblevalid trigger types available to us.

    The possible configurations are

  • 8/12/2019 Triggers Notes

    2/2

    -!F#R! "+(!RT row-!F#R! "+(!RT statementFT!R "+(!RT rowFT!R "+(!RT statement-!F#R! UPDT! row

    -!F#R! UPDT! statementFT!R UPDT! RowFT!R UPDT! statement-!F#R! D!!T! row-!F#R! D!!T! statementFT!R D!!T! rowFT!R D!!T! statement

    +ame (tatement level Row levelBEFORE option Oracle fires trigger only once

    before executing thetriggering statement

    Oracle fires trigger beforemodifying each row affectedby the triggering statement

    AFTER option Oracle fires trigger only oncebefore executing thetriggering statement

    Oracle fires trigger beforemodifying each row affectedby the triggering statement

    Instead of TriggerThese Triggers are Defined on a 0iew rather than a table.1ou can use "+(T!D #F TR"''!R to tell oracle what to do instead of performingactions that invo2ed the trigger.