My SQL Part4
My SQL Part4
[before | after] [before | after]: This specifies when the trigger will be executed.
{insert | update | delete}: This specifies the DML operation.
{insert | update | delete} on [table_name]: This specifies the name of the table associated with the trigger.
[for each row]: This specifies a row-level trigger, i.e., the trigger will be
on [table_name]
executed for each row being affected.
[trigger_body]: This provides the operation to be performed as trigger is fired
BEFORE triggers run the trigger action before the triggering statement is
run. AFTER triggers run the trigger action after the triggering statement is
[trigger_body] run.
Using MySQL Triggers
Every trigger associated with a table
has a unique name and function based
on two factors:
1. Time. BEFORE or AFTER a
specific row event.
2. Event. INSERT, UPDATE or
DELETE.
Create Triggers
Use the CREATE TRIGGER CREATE TRIGGER <trigger name> <trigger
time > <trigger event>
statement syntax to create a new
ON <table name>
trigger:
FOR EACH ROW
<trigger body>;