What is the most portable way to check whether a trigger exists in SQL Server?

后端 未结 9 1792
醉酒成梦
醉酒成梦 2020-12-14 05:50

I\'m looking for the most portable method to check for existence of a trigger in MS SQL Server. It needs to work on at least SQL Server 2000, 2005 and prefe

9条回答
  •  南笙
    南笙 (楼主)
    2020-12-14 06:10

    There's also the preferred "sys.triggers" catalog view:

    select * from sys.triggers where name = 'MyTrigger'
    

    or call the sp_Helptrigger stored proc:

    exec sp_helptrigger 'MyTableName'
    

    But other than that, I guess that's about it :-)

    Marc

    Update (for Jakub Januszkiewicz):

    If you need to include the schema information, you could also do something like this:

    SELECT
        (list of columns)
    FROM sys.triggers tr
    INNER JOIN sys.tables t ON tr.parent_id = t.object_id
    WHERE t.schema_id = SCHEMA_ID('dbo')   -- or whatever you need
    

提交回复
热议问题