Brian Cryer

 

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.



About the author: is a dedicated software developer and webmaster. For his day job he develops websites and desktop applications as well as providing IT services. He moonlights as a technical author and consultant.