获取所有触发器,函数和存储过程的列表

时间:2012-10-04 20:38:20

标签: sql-server

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

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

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

2 个答案:

答案 0 :(得分: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

答案 1 :(得分:2)

程序

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搜索了