From the course: MySQL Database Administration

Unlock this course with a free trial

Join today to access over 24,500 courses taught by industry experts.

Triggers

Triggers

- [Instructor] All right. We are ready to start talking about creating triggers. So MySQL allows us to create triggers where we can prescribe certain actions on a table to trigger one or more actions somewhere else. We can prescribe that our triggered action occurs either before or after the insert, or before or after an update or a delete. Triggers are a very common way to make sure that related tables remain in sync as they get updated with new data over time. So before I jump into workbench, I want to walk you through what I'm going to do there first. In the bottom half of the screen on the right we have the result grid for our inventory table in our thrift shop schema. And we're going to be creating a trigger here that will update this table whenever a customer makes a purchase. So this is a pretty common type of a trigger where here we're tracking inventory, and then we have another table that tracks purchases. And every time somebody purchases an item, we need to remove one item…

Contents