0
2.4kviews
Explain the Triggers in SQL with two examples

Mumbai University > Information Technology > Sem 5 > Advanced Database Management System

Marks: 5M

Year: Dec 2014, May 2015

1 Answer
0
12views

Triggers:

  1. Trigger is a procedure that is automatically invoked as a response to specific change to database and is typically specified by the administrator.
  2. The trigger has 3 main parts:-
  3. Event: - the change to the database which activates trigger.
  4. Condition: - A queue or test that items when trigger is activated.
  5. Action: - If the condition is true then the procedure is executed that procedure is called action.
  6. To design a trigger there are following requirements:
  7. Specify conditions under which trigger is to be executed.
  8. Specify actions to be taken when trigger is executed.
  9. A trigger has power to
  10. Make sure that a column is filled with default information.
  11. Make sure that an audit row is inserted into another table.
  12. After finding that new information is inconsistent with other stuff in database, raise an error that will cause the entire transaction to be rolled back.
  13. Dropping triggers:

    To drop a trigger:- Drop trigger <trigger_name>;

  14. Disable or enable trigger

    To disable or enable a trigger:- Alter trigger <trigger_name><disable enable="">

  15. Basic trigger syntax:

    Create trigger <trigger_name>
    <Before/after><insert/update/delete> on <table_name>
    New as <new row_name>
    For each row [when (<trigger_condition>)]
    Begin 
    <trigger_body>
    end
    
Please log in to add an answer.