HiveBrain v1.2.0
Get Started
← Back to all entries
patternsqlMinor

Can I be notified of a rollback in my DDL Trigger?

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
cantriggernotifiedrollbackddl

Problem

I'd like DDL changes in SQL Server to trigger an external process (outside of SQL). The problem is, is there a way for me to be notified via my trigger that a rollback occurred?

For instance, with the following:

BEGIN TRAN

CREATE TABLE [dbo].[TestRollbackTable](
    col1 varchar(100) NOT NULL)

ROLLBACK


A DDL trigger on CREATE_TABLE would be called, but nothing seems to be called with the ROLLBACK. And since my trigger is calling an external process, it is not automatically subjected to the rollback. How can I catch the fact that the ROLLBACK negated that action?

Solution

Don't use DDL triggers. Use Event Notifications instead. Event Notifications convey the very same data as DDL triggers and occur on the very same events, but they are asynchronous and loosely coupled. You get notified only after the original DDL committed. If the DDL rolls back, you don't get any notification. It seems to be exactly what you need.

Context

StackExchange Database Administrators Q#13422, answer score: 3

Revisions (0)

No revisions yet.