MySQL Trigger - What is a Trigger in MySQL? Define different types of Trigger?

What is a Trigger in MySQL? Define different types of Trigger

A trigger is a set of code which is executed in response to some event.

Example

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 Trigger

A 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.
MySQL - What is the difference between CHAR_LENGTH and LENGTH?
MySQL CHAR_LENGTH and LENGTH - The basic difference between RPC and JMS lies in the way they message. RPC uses synchronous messaging....
MySQL - Explain the difference between BOOL, TINYINT and BIT.
The basic difference between RPC and JMS lies in the way they message. RPC uses synchronous messaging....
MySQL ENUMs - What are ENUMs used for in MySQL?
MySQL ENUMs - Using Enum can restrict the number of values that can be allowed to go inside a table.....
Post your comment