O'Reilly logo

Microsoft SQL Server 2014 Unleashed by Paul Bertucci, Alex T. Silverstein, Chris Gallelli, Ray Rankins

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating DDL Triggers

The basic syntax for creating a DDL trigger follows:

CREATE TRIGGER trigger_nameON { ALL SERVER | DATABASE }[ WITH <ddl_trigger_option> [ ,...n ] ]{ FOR | AFTER } { event_type | event_group } [ ,...n ]AS { sql_statement  [ ; ] [ ...n ] | EXTERNAL NAME < method specifier >  [ ; ] }

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 27.9 illustrates the creation of a DDL trigger that is scoped at the database level and prevents table-level changes.

LISTING 27.9 A Database-Scoped DDL Trigger for Tables

CREATE TRIGGER tr_TableAuditON DATABASEFOR CREATE_TABLE, ALTER_TABLE, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required