- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How is it possible for a MySQL trigger to execute multiple statements?
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 −
Example
mysql> Create Trigger before_inser_studentage BEFORE INSERT ON student_age FOR EACH ROW BEGIN 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)
Advertisements