1.

TRIGGERS IN MYSQL

Answer»

Triggers are DBMS objects which are associated with tables. Triggers are fired when any one of the DML statements (INSERT, DELETE or UPDATE) is activated.

There are two types of triggers,


  • Row Level Triggers: A trigger is an instruction that causes a row to trigger to be fired once for each row affected by an insert, update, or delete statement. The row trigger is fired automatically.

  • Statement Level Trigger: Trigger is fired once regardless of the number of DML statements.

There are six types of triggers, namely,


  • Before Insert: Activated before insertion.

  • After Insert: Activated after insertion.

  • Before Update: Activated before updating.

  • After Update: Activated after updating.

  • Before Delete: Activated before deletion.

  • After Delete: Activated after deletion.

COMMANDFUNCTIONSYNTAX
create triggerCreates a new trigger on an existing table. >CREATE TRIGGER TRIGGERNAME
BEFORE | AFTER INSERT | UPDATE| DELETE
ON TABLENAME FOR EACH ROW
TRIGGERBODY;
drop triggerDeletes an existing trigger.> DROP TRIGGER TRIGGERNAME;
show all triggersDisplays all the triggers in the database.> SHOW TRIGGERS FROM | IN DATABASE_NAME WHERE SEARCH_CONDITION;



Discussion

No Comment Found