Creating DDL Triggers

The basic syntax for creating a DDL trigger follows:

image

The best way to illustrate the use of the DDL trigger syntax and power of these triggers is to look at a few examples. The example shown in Listing 30.14 illustrates the creation of a DDL trigger that is scoped at the database level and prevents table-level changes.

Listing 30.14 A Database-Scoped DDL Trigger for Tables

image

This trigger is fired whenever the CREATE, ALTER, or DROP TABLE statements are executed. Consider, for example, the following statements that can be run ...

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.