Triggers and Multistatement Transactions

Now let’s look at another example. First, you need to create a trigger to enforce referential integrity between the titles table and publishers table:

image

Next, for the trigger to take care of the referential integrity, you might first need to disable the foreign key constraint on the titles table with a command similar to the following:

alter table titles nocheck constraint FK__titles__pub_id__0F424F67

Note

The system-generated name for the foreign key constraint may possibly be different on your database. You can use sp_helpconstraint titles to verify the name of the foreign key constraint on the pub_id ...

Get Microsoft® SQL Server 2008 R2 Unleashed 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.