Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • SQL Server : List all trigger associated with a table with SQL Server

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 724
    Comment on it

    During management of SQL server database many  times  we need to get list all triggers in SQL Server database with table name and table's schema . Following query can be used to get the desired result.

    SELECT 
         sysobjects.name AS [Trigger Name] 
        ,USER_NAME(sysobjects.uid) AS [Trigger Owner] 
        ,SYS.name AS [Table Schema] 
        ,OBJECT_NAME(parent_obj) AS [Table Name] 
        ,OBJECTPROPERTY( id, 'ExecIsUpdateTrigger') AS [Is Update] 
        ,OBJECTPROPERTY( id, 'ExecIsDeleteTrigger') AS [Is Delete] 
        ,OBJECTPROPERTY( id, 'ExecIsInsertTrigger') AS [Is Insert] 
        ,OBJECTPROPERTY( id, 'ExecIsAfterTrigger') AS  [Is After] 
        ,OBJECTPROPERTY( id, 'ExecIsInsteadOfTrigger') AS [Is InsteadOf] 
        ,OBJECTPROPERTY(id, 'ExecIsTriggerDisabled') AS [Disabled] 
    FROM sysobjects 
    INNER JOIN sysusers 
        ON sysobjects.uid = sysusers.uid 
    INNER JOIN sys.tables TAB 
        ON sysobjects.parent_obj = TAB.object_id 
    INNER JOIN sys.schemas SYS 
        ON TAB.schema_id = SYS.schema_id 
    WHERE sysobjects.type = 'TR' 

     

     

    However if you simply want to find all trigger associated with a table with SQL Server , you can use the SQL Server Management Studio(SSMS). You just need to go to the table name and expand the Triggers node to view a list of triggers associated with it.


    Alternatively you can use sp_helptrigger to find the list  of  triggers  associated  with the tables. The table name needs to be passed in as parameter to get the result.

     

    Hope the above article helps you in solving a common problem while working with triggers in SQL server.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: