25
Using Triggers
In this chapter, you’ll learn what triggers are and why and how they are used. You’ll also learn the syntax for creating and using them.
Understanding Triggers
Note
This Chapter Requires MySQL 5 Support For Triggers Was Added To MySQL 5. Therefore, This Chapter Is Applicable To MySQL 5 Or Later Only.
MySQL statements are executed when needed, as are stored procedures. But what if you want a statement (or statements) to be executed automatically when events occur? For example:
Every time a customer is added to a database table, you want to check that the phone number is formatted correctly and that the state abbreviation is in uppercase.
Every time a product is ordered, you want to subtract the ordered quantity from the ...
Get MySQL Crash Course, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.