What is a Trigger in MySQL? Define different types of TriggerA trigger is a set of code which is executed in response to some event.
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.
1. When do you want the trigger to execute? This can be either BEFORE or AFTER
2. What do you expect the trigger to do? This can be INSERT UPDATE DELETE
3. On which table you want the trigger to run? (using ON table_name)
4. 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
What is a Trigger in MySQL? Define different types of TriggerA trigger in MySQL is a database object that is associated with a table. A trigger is fired, when a particular event occurs for the table. Triggers are used to perform validation checks on data values for insertion or to perform calculations on values for updatation.
They are 2 types of triggers
1. Before Trigger - Before Trigger fires before the execution of INSERT, DELETE and UPDATE commands.
2. After Trigger - After trigger fires after the execution of INSERT, DELETE and UPDATE commands.