views:

1355

answers:

3

I am using SQL Advantage and need to know what the SQL is to identify the triggers associated with a table. I don't have the option to use another tool so the good old fashioned SQL solution is the ideal answer.

A: 
select *
from sysobjects
where type = "TR"

Taken from here.

Ray
Thanks Ray, I searched for along time yesterday but never found that article. It has a bounty of useful information in there.
Bill Rawlinson
I would have just added my answer clarification to yours but I can't edit an answer. I think because I didn't have community wiki checked when I created the question.
Bill Rawlinson
+2  A: 

I also found out that

sp_depends <object_name>

will show you a lot of information about a table, including all triggers associated with it. Using that, along with Ray's query can make it much easier to find the triggers. Combined with this query from Ray's linked article:

sp_helptext <trigger_name>

and you can see the definition of the trigger:

sp_depends <trigger_name>

will also show you all tables related to a trigger

Bill Rawlinson
A: 

I believe there is (or at least 'was') some issue where dependency information is not always accurate. Therefore I would attempt to approach it like this :

select name
from sysobjects
where xtype='TR'
and id in (select id from syscomments where text like '%MY-TABLE-NAME%')

Good luck.

PS-This is untested code, leave a comment if it doesn't work, and I'll fix it.

John MacIntyre