A trigger is a database object that is associated with a table and that is defined to activate (or "trigger") when a particular kind of event occurs for that table. This chapter describes how to define and use triggers in MySQL. It covers the following exam topics:
The examples in this chapter require a table that can be modified. To avoid changing the original world database tables, we'll use a table named Capital that contains information about the capital city in each country. Create the Capital table by using the following statement: mysql> CREATE TABLE Capital -> SELECT Country.Name AS Country, City.Name AS Capital, -> City.Population -> FROM Country, City -> WHERE Country.Capital = City.ID; Query OK, 232 rows affected (0.13 sec) Records: 232 Duplicates: 0 Warnings: 0 |