locked
Check if there is trigger RRS feed

  • Question

  • Hi,

    How can I check if there is trigger for one table, and if yes disable?

    if ( there is trigger in cm_template = yes )

       ALTER TABLE cm_template DISABLE TRIGGER TRG_cm_template

    else

      do stuff...

    Since I try disable one trigger in a table which there is not trigger I think I'll receive one error. am I right?

    cheers,

    Monday, September 4, 2006 10:40 PM

Answers

  • If you are using 2005, this is really easy:

    select object_name(parent_id) as table_name, name as trigger_name, is_disabled
    from sys.triggers

    For 2000, you can use:

          SELECT OBJECT_NAME (parent_obj), name,
                          OBJECTPROPERTY (id, 'ExecIsTriggerDisabled') as is_disabled
          FROM  sysobjects
          WHERE  type = 'TR'

    Credit: By Srinivas Sampath MCSE, MVP (SQL Server) in his article: http://sqljunkies.com/Article/F5783CE9-BA74-4657-BF9D-1139BCC3096B.scuk

     

    Tuesday, September 5, 2006 12:57 AM