2

Is there a way to determine if a trigger on any given table affects one other specific table?

My actual problems is rows being deleted from a table, and I am confident it happens from a trigger on another table. I need to find this "other table" (there are several hundred tabels).

Thx in advance!

Regards /Snedker

Martin Smith
  • 438,706
  • 87
  • 741
  • 845

1 Answers1

4

You can use

SELECT def,
        t.*
FROM sys.triggers t
CROSS APPLY (SELECT OBJECT_DEFINITION(object_id)) C(def)
WHERE def LIKE '%DELETE%' AND def LIKE '%your_table%'

If that doesn't find anything and you want to broaden the search you can use

SELECT *
FROM sys.sql_modules
WHERE definition LIKE '%DELETE%' AND definition LIKE '%your_table%' 

If that still doesn't work and you think that the query might be being sent by an application you can use extended events to get to the bottom of things as per my answer here.

Community
  • 1
  • 1
Martin Smith
  • 438,706
  • 87
  • 741
  • 845