Home » Technology » SQL query to find existing triggers in your DB

SQL query to find existing triggers in your DB

USE myAwesomeDatabase
SELECT  table_name = OBJECT_NAME(parent_object_id) ,
        trigger_name = name ,
        trigger_owner = USER_NAME(schema_id) ,
        OBJECTPROPERTY(object_id, 'ExecIsUpdateTrigger') AS isupdate ,
        OBJECTPROPERTY(object_id, 'ExecIsDeleteTrigger') AS isdelete ,
        OBJECTPROPERTY(object_id, 'ExecIsInsertTrigger') AS isinsert ,
        OBJECTPROPERTY(object_id, 'ExecIsAfterTrigger') AS isafter ,
        OBJECTPROPERTY(object_id, 'ExecIsInsteadOfTrigger') AS isinsteadof ,
        CASE OBJECTPROPERTY(object_id, 'ExecIsTriggerDisabled')
          WHEN 1 THEN 'Disabled'
          ELSE 'Enabled'
        END AS status
FROM    sys.objects
WHERE   type = 'TR'
ORDER BY OBJECT_NAME(parent_object_id)
This works great – very handy to have when you need to see what triggers are on what tables in your database!
PS – I used the sample code tag in the HTML view to ‘force’ the single quotes to behave correctly in the code snippet above. Thank you to HTML Goodies for a great article on this!
PSS – I should also add that I great information with these 2 articles regarding triggers – UBER-helpful!!

6 thoughts on “SQL query to find existing triggers in your DB

  1. Kim, I like it! That would be very helpful to be able to see where I have triggers that might be causing issues. One thing, though. I couldn’t quite just copy and paste your code because of those darn left ‘ and right ’ single quotes. I know you can use ' to get the correct ' but I’m sure there has to be an easier way to do it.

    • Hey David,
      I just copied/pasted into SSMS and it ran great without any changes, so I don’t know about the left & right ‘ – I hope you get it to work (at least it’s a pretty small amount of code to hand-edit).


Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s