Home
How To ...
Trouble shooting
 

Cry How to...

Test if Trigger exists


To test if a trigger exists:

if exists (select * from sysobjects where name='<trigger_name>' and xtype='TR')
    print 'Trigger exists'
else
    print 'Trigger does not exist'

where <trigger_name> is the name of the trigger. For example:

if exists (select * from sysobjects where name='tD_Employee' and xtype='TR')
    print 'Trigger exists'
else
    print 'Trigger does not exist'

Note:

  • The 'xtype' field in sysobjects denotes the type of object. 'TR' denoting a trigger.

These notes have been tested against SQL Server 7.