Trigger in MySQL
by Geethalakshmi[ Edit ] 2010-09-29 15:15:30
Trigger in MySQL
A trigger is a set of code which is executed in response to some event.
E.g Update employee_perfomance table when a new task is inserted in task table. Here, the trigger is “update” and the event is “inserting a new row”.
A trigger in MySQL is created using CREATE TRIGGER trigger_name. we need to specify the trigger type.
* When do you want the trigger to execute? This can be either BEFORE or AFTER What do you expect the trigger to do? This can be INSERT UPDATE DELETE
* On which table you want the trigger to run? (using ON table_name)
* Lastly, though not mandatory, is FOR EACH ROW if it is used then the trigger will fire once for all records of the table. If it is not specified the trigger will fire once only regardless of the number of records being updated