MySql trigger
By Peter
Trigger is a database object, associated with a table. Trigger does it’s specified function if an event occures such as insert/update/delete records.
Benefits of Triggers in MySQL:
- triggers can change values before insert/update . If you set the trigger to listen on insert/update and the criteria is not met than value will be modifiade this will be applied with the insert.
- triggers can check values on row level insert or update and it’s able to determine what values where deleted or updated to.
Create trigger:
The create trigger above does a simple value check before insert, the ‘for each row’ means in this case that it’s checked every time insert is issued. Finaly set new.age (it works as a variable) the criteria and action for true and false result.
Take a look on the create trigger syntax: