***Welcome to ashrafedu.blogspot.com * * * This website is maintained by ASHRAF***

Posts

    Tuesday 24 May 2022

    Trigger

    A trigger is a statement that is executed upon modification to the database. A trigger is triggered automatically when an associated DML statement is executed.

    A trigger is a stored procedure in database which automatically invokes whenever a special event in the database occurs. 

    A trigger description contains three parts:

    Event: A change to database that activates the trigger

    Condition: A query or test that is run when the trigger is executed

    Action: A procedure that is executed when the trigger is activated and its condition is true.

    Users may not be aware that a trigger was executed as a side effect of the procedure.

    Syntax:

    create trigger [trigger_name]

    [before | after] 

    {insert | update | delete} 

    on [table_name] 

    [for each row] 

    [trigger_body]

    Explanation of syntax:

    1. create trigger [trigger_name]: Creates or replaces an existing trigger with the trigger_name.
    2. [before | after]: This specifies when the trigger will be executed.
    3. {insert | update | delete}: This specifies the DML operation.
    4. on [table_name]: This specifies the name of the table associated with the trigger.
    5. [for each row]: This specifies a row-level trigger, i.e., the trigger will be executed for each row being affected.
    6. [trigger_body]: This provides the operation to be performed as trigger is fired

     

    BEFORE and AFTER of Trigger:

    BEFORE triggers run the trigger action before the triggering statement is run.
    AFTER triggers run the trigger action after the triggering statement is run.

    No comments:

    Post a Comment