Register now or log in to join your professional community.
Firstly, triggers are ways to tell the dbms (database management system) to execute an action whenever a type of action happens to a database object (mostly tables).
Example, we can tell the MySQL DBMS to do something whenever a new row is inserted into a table. We can use a trigger on that table to achieve this.
CREATE TRIGGER triggerName BEFORE DELETE ON tableName
FOR EACH ROW function.
In the short illustration above, we told the dbms (mysql) to run function BEFORE a row is DELETEd from the tableName table. triggerName is just an identifier or a name for the trigger.
The syntax is:
CREATE [DEFINER = { user | CURRENT_USER }] TRIGGER trigger_name trigger_time trigger_event ON tbl_name FOR EACH ROW trigger_body trigger_time: { BEFORE | AFTER } trigger_event: { INSERT | UPDATE | DELETE }