How is it possible for a MySQL trigger to execute multiple statements?

MySQLMySQLi Database

The MySQL trigger can execute multiple statements with the help of BEGIN…END construct. Within the BEGIN block, we can also use another syntax that is permitted within stored routines such as conditionals and loops. For illustrating the concept, we are using the following example of BEFORE INSERT TRIGGER is having the IF conditional statements −


mysql> Create Trigger before_inser_studentage BEFORE INSERT ON student_age FOR EACH ROW
   IF NEW.age < 0 THEN SET NEW.age = 0;
   ELSEIF NEW.age > 100 THEN SET NEW.age = 100;
   END IF;
END //

Query OK, 0 rows affected (0.30 sec)
Published on 22-Feb-2018 07:42:23