Site sponsored by: Idera Try Idera’s new SQL admin toolset
SQL Server Performance

  • Home
  • Articles
  • Forums
  • Tips
  • Quiz
  • FAQ's
  • Blogs
  • Software
  • Books
  • About Us
RSS Feeds
Sign in | Join


FAQ Topics

All FAQ's
General DBA
General Developer
DBA Performance Tuning
Developer Performance Tuning
Clustering
Error Messages

SQL Server 2008 - Worth the Wait

SQL Server’s first significant upgrade in three years features a number of envelope-pushing enhancements and improvements. Which will have the greatest impact on SQL administration and development? More...
Latest Articles

Slowly Changing Dimensions in SQL Server 2005
Audit Data Modifications
SQL Server 2008’s Management Data Warehouse
Same Report but Different Methods in SQL Server Reporting Services ...

More     
 
Latest FAQ's

How to Integrate Performance Monitor and SQL Profiler
SSIS Lookups are Case Sensitive
Convert Number to Words in SSRS
After installing SP2 on SQL Server 2005 x64, when trying to ...

More     
   
Latest Software Reviews

SQL Server DBA Dashboard
SwisSQL DBChangeManager
SQLMesh - SQL Server Search Tool
SoftTreeTech SQL Assistant

More     

How do you create trigger on system tables?


Printer friendly

First of all, you should refrain from messing around with SQL Server's system tables, unless you are told to and are guided by Microsoft. You are running an unsupported system if you modify the system tables!

But if you don't want to listen to the above advice, why would one want to create a trigger on system tables?

The following two reasons seem to be among the most often asked about:

  • Creating a trigger on sysobjects in order to take some action when a new object is created or an existing object is modified. 

  • Creating a trigger on sysusers or sysxlogins in order to take some action when a new user is added or already existing ones are about to be modified.

To be fair, the build-in support in SQL Server 2000 for these reasonable requirements is poor.

Having said that, it is technically possible to create trigger on system tables. Or at least to create trigger on some of the system tables. But they are not guaranteed to fire.

Now, what is meant with "on some of the system tables"? Well, to put it in easy words, there are two types of system tables: those that accept triggers, and those that don't. While:

use msdb
go
create trigger test on dbo.backupfile for insert, update, delete as select 'Hallo Welt'
drop trigger test
 
The command(s) completed successfully.

obviously finishes successfully, but you will receive:

Server: Msg 229, Level 14, State 5, Procedure test, Line 4 CREATE TRIGGER permission denied on object 'sysobjects', database 'master', owner 'dbo'.

when trying to execute the following statement:

use master
go
create trigger test on dbo.sysobjects for insert, update, delete as select 'Hallo Welt'

So, what can you do in such cases where you need to determine modifications on the system tables? Well, you can run a trace to capture these events. You can also activate SQL Server's build-in C2 auditing, which is likely to be an overkill, since it captures everything, use some third-party tools that offer such functionality, or simply wait for the next version with its' improved functionality in this area.



Comments:
Your Name  
Email    
(Emails will not be displayed on the site or used for promotional purposes)
Comment  


Type characters in the image
 
 (case sensitive)

 
 
 







Home | Peformance Articles | Audit Articles | Business Intelligence Articles | Clustering Articles | Developer Articles | Reporting Services Articles | DBA Articles | ASP.NET / ADO.NET Articles | DBA FAQ's | Developer Peformance FAQ's | DBA Peformance FAQ's | Developer FAQ's | Clustering FAQ's | Error Messages | Audit Tool Reviews | Backup Tool Reviews | Coding Tool Reviews | Compare Tool Reviews | Documentation Tool Reviews | Design Tool Reviews | Monitoring Tool Reviews | Log Tool Reviews | Reporting Tool Reviews | Clustering Tool Reviews | Security Tool Reviews | Change Management Tool Reviews | Remote Access Tool Reviews | Book Reviews | Security Tool Reviews | QDPMA Performance Tuning | ADO.NET / ASP.NET | Administration | Analysis/OLAP Services | Application Development | Configuration | Components | ETL | Hardware | High Availability | Hints | Index | Misc | Operating Systems | Performance Tuning | Replication | T-SQL | Views