Transact-SQL To Find Triggers In a Database

I recently helped a colleague of mine with some troubleshooting surrounding triggers.  Because he is more app code focused he wasn’t immediately thinking “trigger” with the data issues he was seeing.

If you are working in an database that is not your creation you might find this script helpful.  The following T-SQL touches four catalog views and returns all triggers and what function they support:

SELECT s.name AS SchemaName
    ,ta.name AS TableName
    ,t.name AS TriggerName
    ,CASE
        WHEN t.is_disabled = 1 THEN 'Yes'
        ELSE 'No'
    END AS IsDisabled
    ,CASE
        WHEN t.is_instead_of_trigger = 1 THEN 'Yes'
        ELSE 'No'
    END AS IsInsteadOfTrigger
    ,te.type_desc AS TriggerType
    ,t.create_date AS DateCreated
    ,t.modify_date AS LastModifiedDate
FROM sys.triggers AS t
    INNER JOIN sys.trigger_events AS te ON te.[object_id] = t.[object_id]
    INNER JOIN sys.tables AS ta ON ta.[object_id] = t.parent_id
    INNER JOIN sys.schemas AS s ON s.[schema_id] = ta.[schema_id];

Posted by: whitneyw
Posted on: 6/3/2009 at 11:03 PM
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (3) | Post RSSRSS comment feed

Comments

Nick Olson United States

Thursday, June 04, 2009 1:00 AM

Nick Olson

Just had to do this as well, you can drop the inner join to sys.tables by using the OBJECT_NAME built-in function and pass the trigger's parent_id into it.  You might be able to use it on the schema_id as well.

Yachtcharter Griechenland Greece

Thursday, September 24, 2009 2:36 AM

Yachtcharter Griechenland

Wow, I never knew that Transact-SQL To Find Triggers In a Database. That's pretty interesting...

Yachtcharter Griechenland Greece

Thursday, September 24, 2009 2:38 AM

Yachtcharter Griechenland

That's great, I never thought about Transact-SQL To Find Triggers In a Database like that before.

Comments are closed