Creating a Trigger
Next, we’ll use the following syntax to create our trigger (line numbers are added on the left for reference and are not part of the syntax):
1 DELIMITER $$
2
3 CREATE TRIGGER name_of_trigger BEFORE/AFTER UPDATE/DELETE/INSERT ON name_of_table FOR EACH ROW
4
5 BEGIN
6 -- Actions to take
7 END $$
8
9 DELIMITER ;
This syntax may look overwhelming at first. Do not worry, we’ll go over each keyword one by one.
On line 1, we have a new keyword - DELIMITER.
A delimiter is a character or sequence of characters that specifies the end of a SQL statement. Recall that previously, we have always used ; to specify the end of our SQL statements? We can change that if we want.
The code on line 1 (DELIMITER $$) tells MySQL that we want to use $$ as the delimiter for our CREATE TRIGGER statement (from lines 3 to 7).
Why do we need to do that?
The reason for...