Executing Triggers

Triggers are very much like stored procedures in that you must define them to store them in the database. It is also true that like a stored procedure, triggers are not executed when you create them. However, the difference between stored procedures and triggers comes in when they are executed. You control when a stored procedure is executed, whereas the SQL Server controls when a trigger is executed. To see how this works, we will execute an UPDATE statement on the Employees table for which we created a trigger in the previous section. The following UPDATE statement will make a minor change to the Employees table:

Update Employees
Set City = 'New york'
Where City = 'Seattle'


 2 rows modified (This is the trigger ...

Get Sams Teach Yourself Transact-SQL in 21 Days, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.