Personal tools
You are here: Home SQL Server How To's How to discover which action fires a specific trigger in SQL Server
Navigation
Log in


Forgot your password?
 
Document Actions

How to discover which action fires a specific trigger in SQL Server

It's not uncommon the need to discover which action fires a specific trigger (in other words which actions that trigger is related).

-- First Let's Create The Table

create table tbl (id int)
go

-- Create a generic trigger for Insert

create trigger trgI on tbl
for insert
as
 print 'do nothing'
go

-- Create a generic trigger for Update

create trigger trgU on tbl
for update
as
 print 'do nothing'
go

-- Create a generic trigger for Delete

create trigger trgD on tbl
for delete
as
 print 'do nothing'
go

-- Create a generic trigger for all the actions

create trigger trdA on tbl
for insert, update, delete
as
 print 'do nothing'
go

-- There's no column to inform the related action

select * from sysobjects where type = 'tr'
select * from sys.objects where type = 'tr'
select * from sys.triggers

-- We can see this information using objectproperty funcion

select object_name(parent_id) as referenced_table, name,
 objectproperty(object_id,'ExecIsInsertTrigger') as IsInsert,
 objectproperty(object_id,'ExecIsUpdateTrigger') as IsUpdate,
 objectproperty(object_id,'ExecIsDeleteTrigger') as IsDelete
from sys.triggers

Security Awareness
Would you like your company to implement gamification into your security awareness program?





Polls