SQL Code Snippets : Search Triggers

List all the triggers belong to a table

select o.name,p.name
from sys.objects o
join sys.objects p on o.parent_object_id = p.object_id
where o.type = ‘TR’
and p.name = ‘table_name’

Find the table a trigger belongs to

select o.name,p.name
from sys.objects o
join sys.objects p on o.parent_object_id = p.object_id
where o.type = ‘TR’
and o.name = ‘trigger_name’

Search the contents of a trigger

select o.name,p.name
from sys.objects o
join sys.objects p on o.parent_object_id = p.object_id
where o.type = ‘TR’
and object_definition(o.object_id) like ‘%search string%’

Advertisements