1

如何获取数据库中所有触发器、函数和过程的列表?是否有可能只获得用户的触发器、功能、程序?

select Name from sys.all_objects where type = 'udp'

此查询将返回所有用户程序的列表?

4

2 回答 2

6
select type, name
from sys.objects
where type in (
  'tr', -- triggers
  'p', -- procedures
  'if','fn','tf' -- functions
  --,'fs','ft' -- CLR functions
  )
  and is_ms_shipped = 0 -- user-defined

参考:sys.objects

于 2012-10-04T21:12:51.743 回答
3

对于程序

select * from sys.procedures

对于函数

SELECT * FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_TYPE = 'FUNCTION'

用于触发器

 SELECT S2.[name] TableName, S1.[name] TriggerName, CASE WHEN S2.deltrig = s1.id THEN 'Delete' WHEN S2.instrig = s1.id THEN 'Insert' WHEN S2.updtrig = s1.id THEN 'Update' END 
'TriggerType' , 'S1',s1.*,'S2',s2.* FROM sysobjects S1 JOIN sysobjects S2 ON S1.parent_obj = S2.[id] WHERE S1.xtype='TR'

这个我不太清楚,google了一下

于 2012-10-04T20:52:54.847 回答