zaagan
8/4/2019 - 7:02 AM

MS SQL Get All Triggers In DB

MS SQL Get All Triggers In DB

SELECT
    [so].[name] AS [trigger_name],
    USER_NAME([so].[uid]) AS [trigger_owner],
    USER_NAME([so2].[uid]) AS [table_schema],
    OBJECT_NAME([so].[parent_obj]) AS [table_name],
    OBJECTPROPERTY( [so].[id], 
              'ExecIsUpdateTrigger') AS [IsUpdate],
    OBJECTPROPERTY( [so].[id],  
              'ExecIsDeleteTrigger') AS [IsDelete],
    OBJECTPROPERTY( [so].[id], 
              'ExecIsInsertTrigger') AS [IsInsert],
    OBJECTPROPERTY( [so].[id],
              'ExecIsAfterTrigger') AS [IsAfter],
    OBJECTPROPERTY( [so].[id],
              'ExecIsInsteadOfTrigger') AS [IsInsteadof],
    CASE OBJECTPROPERTY([so].[id], 
              'ExecIsTriggerDisabled')
          WHEN 1 THEN 'Disabled'
          ELSE 'Enabled'
        END AS status
FROM sysobjects AS [so]
INNER JOIN sysobjects AS so2 ON so.parent_obj = so2.Id
WHERE [so].[type] = 'TR'

-- SOURCE: https://stackoverflow.com/a/4307260