forum

Home / DeveloperSection / Forums / What is the best way to check whether a trigger exists in SQL Server?

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

John Smith 4311 16-Oct-2012
I am looking for the most portable method to check for existance of a trigger in MS SQL Server. It needs to work on at least SQL Server 2000, 2005 and preferably 2008.

The information does not appear to be in INFORMATION_SCHEMA, but if it is in there somewhere, I would prefer to use it from there.

I do know of this method:

if exists (
    select * from dbo.sysobjects
    where name = 'MyTrigger'
    and OBJECTPROPERTY(id, 'IsTrigger') = 1
)
begin
end

But I am not sure whether it works on all SQL Server versions.

So my questions are:

    Is the above the "best" way?
    Are there any alternative methods?
    What are their pros and cons?


Updated on 16-Oct-2012
I am best.

Can you answer this question?


Answer

1 Answers

Liked By