Executing code with triggers
Triggers are code that we associate with a table to be executed when certain actions occur, for example, after a new INSERT
statement in the book
table. The action does not need to happen within phpMyAdmin.
Contrary to routines that are related to an entire database and are visible on the database's Structure page, triggers for each table are accessed from this specific table's Structure page.
Note
Prior to MySQL 5.1.6, we needed the SUPER
privilege to create and delete triggers. In version 5.1.6, a TRIGGER
table-level privilege was added to the privilege system. Hence, a user no longer needs the powerful SUPER
privilege for these tasks.
In order to perform the following exercise, we will need a new INT
column—total_page_count
—in our author
table.
The idea here is that every time a book is created, its page count will be added to the total page count of the books from this author. Some people may advocate that it would be better not to keep a separate column for...