Chapter 33. Triggers

33.1 Introduction

A database server is passive by nature. It performs an action only if we explicitly ask for it with, for example, an SQL statement. This chapter describes the database concept that turns a passive database server into an active one. This concept is called a trigger. As with stored procedures, we start by giving a definition:

A trigger is a piece of code consisting of procedural and declarative statements stored in the catalog and activated by the database server if a specific operation is executed on the database—and only then when a certain condition holds.

A trigger shows many similarities to a stored procedure. First, the trigger is also a procedural database object stored in the catalog. Second, the ...

Get SQL for MySQL Developers: A Comprehensive Tutorial and Reference 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.