Thursday, July 28, 2011

Find all the triggers on a table?

We all know that there are three types of triggers that can be created on a table, namely the insert, update and delete trigger. What if someone asks us to find out trigger associated to a table. Well the first answer would be very much easy - Simply type -

sp_depends <<Table Name>>

and we will get all the objects dependent on the table. The only catch here is that sysdepends table is the prime table that is being used by sp_depends stored procedure to extract the required information and as per the history related to this table - This isn't very reliable because Sybase SQL Server and Microsoft SQL Server both are very bad in maintaining entries in this table. So whats the answer to our problems.

Well, the answer to this is pretty much easy. Simply query the sysobjects table for the table under consideration and check for the following column entries -

1. instrig - For insert trigger object id.
2. updtrig - For update trigger object id and
3. deltrig - For delete trigger object id

Well, apart from these three trigger entries there is one more reserved trigger type which is select trigger represented by seltrig column in sysobjects, however this isn't used in Sybase ASE.

No comments:

Post a Comment