Use of Triggers in Databse Systems

What are triggers used for, and why are they important in database systems? Provide an example of a situation where a trigger would be appropriate. What would the implementation of this trigger look like?

Solution Preview

A trigger is a special kind of stored procedure that executes automatically whenever an attempt is made to modify data in a table that the trigger protects. Triggers can include most Transact-SQL statements. When an attempt is made to insert, update, or delete data in a table and a trigger for that particular action has been defined on the table, the trigger executes automatically. A trigger cannot be circumvented.

Triggers are used to maintain low-level data integrity, not to return query results. The primary benefit of triggers is that they can contain complex processing logic. You should only use triggers when constraints do not provide the functionality you require.

The following are common reasons to use triggers:
cascade modifications through related ...