1

如何获取与每个表关联的触发器列表?

我试图得到这样的东西:

Table 1 – Trigger for Table 1 – Trigger for Table 1 – Trigger for Table 1

Table 2 – Trigger for Table 2 – Trigger for Table 2 – Trigger for Table 2

只要我可以轻松解释数据,就不必采用这种格式。

4

2 回答 2

2

试试这个——

SELECT 
      object_name = s.name + '.' + o.name
    , trigger_name = t.name
    , o.type_desc
    , is_insert_trigger = OBJECTPROPERTY(t.[object_id], 'ExecIsInsertTrigger')
    , is_update_trigger = OBJECTPROPERTY(t.[object_id], 'ExecIsUpdateTrigger') 
    , is_delete_trigger = OBJECTPROPERTY(t.[object_id], 'ExecIsDeleteTrigger')
    , t.is_instead_of_trigger
    , t.is_disabled
FROM sys.objects o WITH (NOWAIT) 
JOIN sys.schemas s WITH (NOWAIT) ON o.[schema_id] = s.[schema_id]
JOIN sys.triggers t WITH (NOWAIT) ON o.[object_id] = t.parent_id
WHERE o.[type] = 'U'
于 2013-04-12T08:37:14.910 回答
1
SELECT 
 sysobjects.name AS trigger_name 
,USER_NAME(sysobjects.uid) AS trigger_owner 
,s.name AS table_schema 
,OBJECT_NAME(parent_obj) AS table_name 
,OBJECTPROPERTY( id, 'ExecIsUpdateTrigger') AS isupdate 
,OBJECTPROPERTY( id, 'ExecIsDeleteTrigger') AS isdelete 
,OBJECTPROPERTY( id, 'ExecIsInsertTrigger') AS isinsert 
,OBJECTPROPERTY( id, 'ExecIsAfterTrigger') AS isafter 
,OBJECTPROPERTY( id, 'ExecIsInsteadOfTrigger') AS isinsteadof 
,OBJECTPROPERTY(id, 'ExecIsTriggerDisabled') AS [disabled] 
FROM sysobjects 

INNER JOIN sysusers 
ON sysobjects.uid = sysusers.uid 

INNER JOIN sys.tables t 
ON sysobjects.parent_obj = t.object_id 

INNER JOIN sys.schemas s 
ON t.schema_id = s.schema_id 

WHERE sysobjects.type = 'TR'

希望这可以帮助

于 2013-04-12T08:36:49.283 回答