[ACCEPTED]-How do you identify the triggers associated with a table in a sybase database?-sybase

Accepted answer
Score: 12
select *
from sysobjects
where type = 'TR'

Taken from here.


Score: 11

I also found out that

sp_depends <object_name> 

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

sp_helptext <trigger_name>

and 2 you can see the definition of the trigger:

sp_depends <trigger_name>

will 1 also show you all tables related to a trigger

Score: 5

to show triggers and create sql for a table:

select so.name, text
from sysobjects so, syscomments sc
where type = 'TR'
and so.id = sc.id
and text like '%TABLENAME%'


Score: 3
    T.name AS TableName
    ,O.name  TriggerName  
    FROM sysobjects O 
    INNER JOIN sys.tables T ON T.object_id = O.parent_obj
    WHERE O.type = 'TR' AND T.name IN ('tableNames')
ORDER BY TableName


Score: 1

I believe there is (or at least 'was') some 5 issue where dependency information is not 4 always accurate. Therefore I would attempt 3 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 2 is untested code, leave a comment if it 1 doesn't work, and I'll fix it.

Score: 0
  1. Open Sybase Central and navigate to the triggers view.
  2. Click on the "Object Name" column to sort.

The "Object Name" column apparently shows 2 the table associated with the trigger. Scroll 1 down to the table you're interested in.

Score: 0

I would use following code, to make sure 4 you're getting the right objects. Since 3 Sybase 16 this won't be complete anymore, as 2 there might be more triggers of the same 1 type on one table.

    select tr.id, tr.name, tr.type, tr.crdate, tr.loginame
from sysobjects u
  join sysobjects tr on tr.id in (u.instrig, u.deltrig, u.updtrig, u.seltrig)
where u.name = 'TABLENAME'
Score: 0

I am using SQL Anywhere 16 and it's easy 5 to find the triggers of a specific table. When 4 you open the table, there is a tab named 3 'Triggers'. But the query to find all the 2 triggers is a bit different from the answers 1 above:

select * from SYS.SYSTRIGGERS --where trigdefn like '%exec%'
Score: 0


SELECT so.name, Type=(CASE so.type WHEN 'V' Then 'View' WHEN 'P' THEN 'Procedure' WHEN 'TR' THEN 'Trigger' ELSE so.type END)
    FROM sysobjects so, sysdepends d
        d.depid = object_id('MyTblName')
        AND so.id =d.id 
        /* Just triggers 
        AND so.type = 'TR'
    ORDER BY so.type,so.name


More Related questions