This works on SQL Server 2000 and later.
IF OBJECTPROPERTY(OBJECT_ID('{your_trigger}'), 'IsTrigger') = 1 BEGIN ... END
Note that naive handling does not work reliably:
-- This doesn't work for checking for absense IF OBJECTPROPERTY(OBJECT_ID('{your_trigger}'), 'IsTrigger') <> 1 BEGIN ... END
... because if the object does not exist at all, OBJECTPROPERTY returns NULL , and NULL (of course) is not <> 1 (or something else).
In SQL Server 2005 or later, you can use COALESCE to handle this, but if you need to support SQL Server 2000, you will need to structure your statement to deal with three possible return values: NULL (the object does not exist at all) , 0 (it exists, but is not a trigger), or 1 (it is a trigger).
wqw Aug 05 '10 at 14:40 2010-08-05 14:40
source share