Welcome to MSDN Blogs Sign in | Join | Help

Benjamin Wright-Jones

SQL Server Lessons Learned and Notes from the Field (Microsoft Consultancy Services, UK)

News

  • This posting is provided "AS IS" with no warranties, and confers no rights. Use of included script samples are subject to the terms specified on Microsoft.com Locations of visitors to this page
SQL Server 2005 Extended Triggers

Ok, I am impressed with everything in SQL Server 2005, especially extended triggers to capture DDL actions.  I was playing around with these today and I can see how this will be a nice feature, especially for audit trails.  I've included a simple script below.

-- create sample db
create
database trigtestdb
go

use trigtestdb
go
create table tblextrig (eventid int identity, eventdata xml)
go

-- create event driven trigger
create trigger trig_ddl
   
on database
   
for create_table, drop_table, alter_table
as
   
insert tblextrig values (eventdata())
go

-- do some ddl
create table ben (id int)
drop table ben
create table ben (id int)
go

-- check if DML events have been logged by trigger
select eventid, eventdata from tblextrig
go

-- clean up
use master
go

drop database trigtestdb

 

Posted: Wednesday, October 20, 2004 9:10 PM by benjones

Comments

Scott Allen said:

This is a *great* feature. Especially for those production databases where you can prevent those accidental table drops!
# October 21, 2004 4:37 AM

Ramblings of a DBA said:

# October 21, 2004 9:07 PM

Ramblings of a DBA said:

# October 22, 2004 2:04 PM
Anonymous comments are disabled
Page view tracker