Chapter 32. Triggers

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. In this chapter, we describe the database concept that turns a passive database server into an active one. This concept is called a trigger. Just 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 Introduction to SQL: Mastering the Relational Database Language, Fourth Edition/20th Anniversary 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.