Understanding Triggers

Triggers are special stored procedures that are executed automatically when specific database activity occurs. Triggers might be associated with INSERT, UPDATE, and DELETE operations (or any combination thereof) on specific tables.

Unlike stored procedures (which are simply stored SQL statements), triggers are tied to individual tables. A trigger associated with INSERT operations on the Orders table will only be executed when a row is inserted into the Orders table. Similarly, a trigger on INSERT and UPDATE operations on the Customers table will only be executed when those specific operations occur on that table.

Within triggers, your code has access to the following:

  • All new data in INSERT operations

  • All new data and old ...

Get Sams Teach Yourself SQL in 10 Minutes 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.