DDL Triggers

SQL Server supports data definitin language (DDL) triggers, allowing you to trap DDL operations and react to them. You can thus roll back the DDL activity. DDL triggers work synchronously, immediately after the triggering event, similar to the way that DML triggers work. DDL triggers can be database-wide and can react to certain types of DDLs or all DDLs.

The cool thing about DDL triggers is that you can get context information from querying the EVENTDATA function. Event data is an XML payload of data about what was happening when your DDL trigger ran (including information about the time, connection, and user), the type of event that was fired, and other useful data. To get at EVENTDATA data, you have to use the EVENTDATA function ...

Get Programming Microsoft® SQL Server™ 2008 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.