Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Search db for all triggers and list SQL

Author  Topic 

tcarnahan
Starting Member

23 Posts

Posted - 2008-08-30 : 16:07:22
Hi!

I am not new to SQL but I am new to using T-SQL and the system tables.

I inherited a SS2K database that is fairly extensive. I need to examine the SQL coding of all triggers in all instances of the datbase. I have Enterprise Manager, but it would be a lengthy process to open all tables of all instances to examine the SQL coding.

I am able to query system tables but I don't know the schema well enough to do find the information I need.

QUESTION: can someone point me to a T-SQL query that will find all triggers in the SS group and list the following?

- Instance name
- Table name
- Trigger name
- SQL code that makes up the trigger

Any help you can provide would be greatly appreciated!

-- Tom

jezemine
Master Smack Fu Yak Hacker

2886 Posts

Posted - 2008-08-30 : 17:37:04
This is more or less the query that SqlSpec uses:


select --distinct
s.name
,ss.name as tablename
,s.crdate as created
,ObjectProperty(s.id, 'ExecIsUpdateTrigger') as isUpdate
,ObjectProperty(s.id, 'ExecIsDeleteTrigger') as isDelete
,ObjectProperty(s.id, 'ExecIsInsertTrigger') as isInsert
,ObjectProperty(s.id, 'ExecIsAfterTrigger') as isAfter
,ObjectProperty(s.id, 'ExecIsInsteadOfTrigger') as isInsteadOf
,ObjectProperty(s.id, 'ExecIsFirstDeleteTrigger') as isFirstDelete
,ObjectProperty(s.id, 'ExecIsLastDeleteTrigger') as isLastDelete
,ObjectProperty(s.id, 'ExecIsFirstInsertTrigger') as isFirstInsert
,ObjectProperty(s.id, 'ExecIsLastInsertTrigger') as isLastInsert
,ObjectProperty(s.id, 'ExecIsFirstUpdateTrigger') as isFirstUpdate
,ObjectProperty(s.id, 'ExecIsLastUpdateTrigger') as isLastUpdate
,ObjectProperty(s.id, 'ExecIsTriggerDisabled') as isDisabled
,ObjectProperty(s.id, 'ExecIsTriggerNotForRepl') as isNotForReplication
from sysobjects s
join sysobjects ss on s.parent_obj=ss.id
where s.xtype in ('TR')
order by 1 asc


to get the DDL:


select
so.id
,so.name
,case when sc.encrypted=0 then sc.text else '*** code is encrypted ***' end as code
from sysobjects so
join syscomments sc on so.id=sc.id
where 1=1
and so.xtype in ('TR')
order by so.id, sc.colid


note that if the code is long, it may be broken up in to multiple rows in that second query.


elsasoft.org
Go to Top of Page

tcarnahan
Starting Member

23 Posts

Posted - 2008-08-31 : 14:18:10
Thanks! I will give it a try when I get back to work.

-- Tom
Go to Top of Page
   

- Advertisement -