Using Triggers to Define Business Processes

A trigger is a special kind of stored procedure that goes into effect when you modify data in a specified table. Triggers are often created to enforce business rule consistency among logically related data in different tables.

An advantage of triggers is that they are automatic ¾ they work no matter what caused the data modification ¾ a clerk's entry or an application action. Each trigger is specific to one or more of the data modification operations UPDATE, INSERT, or DELETE. The trigger is executed once per SQL statement; it "fires" immediately after the data modification statements are completed. The trigger and the statement that fires it are treated as a single transaction that can be rolled back from within the trigger. If a severe error is detected, the entire transaction automatically rolls back.

Triggers are useful in these ways:

Note Except for the deltitle trigger, the triggers discussed in this chapter are not part of the pubs database included with SQL Server. To work with the examples shown, you must create each trigger by using the CREATE TRIGGER statement. Note that each new trigger for the same operation (INSERT, UPDATE, or DELETE) on a table or column overwrites the previous one without warning. For details about CREATE TRIGGER, see the CREATE TRIGGER statement in the Microsoft SQL Server Transact-SQL Reference.