Trigger In MySQL
Database triggers are SQL statements storing in the database catalog. Once a trigger is activated by database events such as UPDATE, DELETE or INSERT, it will execute either before or after the event that initiated it.
A trigger is a SQL procedure that initiates an action when an event (INSERT, DELETE or UPDATE) occurs.
Syntex:-
If We want edit or modify the trigger,We need click on structure menu in phpmyadmin Then click on details link.
trigger_time:
trigger_time is the trigger action time. It can be BEFORE or AFTER to indicate that the trigger activates before or after each row to be modified.
trigger_event:
trigger_event indicates the kind of statement that activates the trigger. The trigger_event can be one of the following:
1. insert query
2. update query
3. delete query
Example:-
Database triggers are SQL statements storing in the database catalog. Once a trigger is activated by database events such as UPDATE, DELETE or INSERT, it will execute either before or after the event that initiated it.
A trigger is a SQL procedure that initiates an action when an event (INSERT, DELETE or UPDATE) occurs.
Syntex:-
1 | CREATE TRIGGER trigger_name trigger_time trigger_event ON tbl_name FOR EACH ROW trigger_body |
trigger_time:
trigger_time is the trigger action time. It can be BEFORE or AFTER to indicate that the trigger activates before or after each row to be modified.
trigger_event:
trigger_event indicates the kind of statement that activates the trigger. The trigger_event can be one of the following:
1. insert query
2. update query
3. delete query
Example:-
1 2 3 4 5 6 7 8 | delimiter $$ CREATE TRIGGER Employee_Trigger AFTER insert ON employee FOR EACH ROW BEGIN insert into employee_log values (new.id, new.first_name, new.last_name); END $$ |
No comments:
Post a Comment