How do you create trigger on system tables?

          

Interview questions

SQL Server - How do you create trigger on system tables?

Next>>         SQL Server tutorial  

SQL Server - How do you create trigger on system tables? - Feb 27, 2010 at 11:50 AM by Shuchi Gauri

How do you create trigger on system tables? What can be the reasons to create trigger on system tables?

Reasons to create trigger on system tables:

  • One might need to be notified or take some action when a new object is created or modified in sysobjects.
  • One might need to be notified or take some action when a new user is created or modified in sysusers.

Creating trigger:
Use master
Go
Create trigger trigAbc on dbo.sysobjects for insert, update, delete as select ‘Hallo Welt’

SQL Server - How do you create trigger on system tables? - May 05, 2009 at 22:00 PM by Rajmeet Ghai

How do you create trigger on system tables? What can be the reasons to create trigger on system tables?

Even though creating triggers on system tables should be avoided, following are the probable reasons why one would want to create triggers on system tables:

  • To take some action on an event like modification or creation of a new object.
  • To take some action on an event like modification or creation of a new user.

Even though a trigger may be created on a system table, it is less likely they will be fired.

SQL Server - How do you create trigger on system tables? - June 21, 2009 at 09:00 AM by Amit Satpute

Creating a trigger on system tables is done to:

Perform some action when a new object is created or an existing object is modified.
Take some action when a user is added or modified.
To be fair, the build-in support in SQL Server 2000 for these reasonable requirements is poor.
Some system tables accept triggers and some don't.

Example

use msdb
go
create trigger test on dbo.backupfile for insert, update, delete as select 'XYZ'
drop trigger system_trigger_test

At times triggers don’t get created as the permission to access the objects is denied. In such cases trace needs to be used to find out the reason.


Next>>

Also read

What are the differences among batches, stored procedures, and triggers?

Answer - A batch is a group of one or more SQL statements. SQL Server compiles the statements......

How do you create trigger on system tables? What can be the reasons to create trigger on system tables?

Even though creating triggers on system tables should be avoided, following are the probable reasons why one would want to create triggers on system tables.............

SQL Server Database Objects

Table, Data types, Function, Index, Constraint, Rule, Default, Stored Procedures, Trigger, View..........

What are the instances when triggers are appropriate?
What are the restrictions while creating batches in SQL Server?

Answer - CREATE DEFAULT, CREATE PROCEDURE, CREATE RULE, CREATE TRIGGER, and CREATE VIEW statements....



Write your comment - Share Knowledge and Experience


 

 
Latest placement tests
Latest links
 
Latest MCQs
» General awareness - Banking » ASP.NET » PL/SQL » Mechanical Engineering
» IAS Prelims GS » Java » Programming Language » Electrical Engineering
» English » C++ » Software Engineering » Electronic Engineering
» Quantitative Aptitude » Oracle » English » Finance
Home | About us | Sitemap | Contact us | We are hiring