How Triggers Are Defined

As I mentioned in the introduction to this chapter, a trigger is nothing more than a specialized stored procedure that's fired in response to a data modification statement against a table or a view. Triggers can add a powerful dimension to any application that you create, allowing you to react programmatically to the data users are entering into database tables. The only other way to do this would be to code any type of reactionary logic into the application layer. This might not always be the right answer for you.

In the past, the main functionality provided by triggers was enforcing referential integrity—in other words, ensuring that a parent-child relationship was maintained between tables. Today, using primary key ...

Get Writing Stored Procedures for Microsoft SQL Server 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.