Trigger search for table

  • Is there any known way to search triggers in all tables on a db for references to a specific table?

    Thanks for any help you can provide.

  • Hi RandyB,

    quote:


    Is there any known way to search triggers in all tables on a db for references to a specific table?


    this is no complete solution but I hope someone else will provide the missing part

    SELECT * FROM sysobjects WHERE xtype = 'TR' will give you a list of all triggers in a db

    Cheers,

    Frank

    --
    Frank Kalis
    Microsoft SQL Server MVP
    Webmaster: http://www.insidesql.org/blogs
    My blog: http://www.insidesql.org/blogs/frankkalis/[/url]

  • Thanks Frank,

    You got me thinking....

    So I scripted all the tables in the db including triggers and am searching the table name in QA.

    Regards,

    Randy

  • perhaps a better way would be to execute the following code in QA...

    select

    *

    from

    syscomments

    where

    text like '%create trigger%'

    and text like '%TABLE_NAME%'

  • That is excellent...Thanks.

  • If your table name might be part of another table name, you could use a more selective LIKE pattern:

    select so.name

    from sysobjects so

    inner join syscomments sc on sc.id = so.id

    where so.xtype = 'TR' and sc.text like '%[^A-Z0-9_]TABLE_NAME[^A-Z0-9_]%'

  • If you want the name of the table along with the trigger name:

    select tbl.name as TABLE_NAME, trg.name as TRIGGER_NAME

    from sysobjects trg

    inner join syscomments sc on sc.id = trg.id

    inner join sysobjects tbl on tbl.id = trg.parent_obj

    where trg.xtype = 'TR' and sc.text like '%[^A-Z0-9_]sales[^A-Z0-9_]%'

Viewing 7 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic. Login to reply