Triggers are one of the more complex mechanisms available to you for enforcing business rules, data integrity, and consistency inside a database. A trigger is a special kind of stored procedure that's associated with a particular table, and it automatically executes when data in the table is modified.
Using triggers, you can automate the execution of SQL code by having it react to certain events that happen to database tables. In this chapter, you'll learn about the following:
Understanding what triggers are and how they work
Logging table activity using AFTER triggers
Creating triggers that respond to inputting, updating, and deleting data in a table
Because only SQL Server, Oracle, and DB2 support triggers, we won't cover MySQL or Access in this chapter. However, each database platform implements triggers slightly differently, so you'll see the code for creating and working with triggers in three Relational Database Management System (RDBMS)-specific sections.