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
    • 728
    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.

    1. SELECT
    2. sysobjects.name AS [Trigger Name]
    3. ,USER_NAME(sysobjects.uid) AS [Trigger Owner]
    4. ,SYS.name AS [Table Schema]
    5. ,OBJECT_NAME(parent_obj) AS [Table Name]
    6. ,OBJECTPROPERTY( id, 'ExecIsUpdateTrigger') AS [Is Update]
    7. ,OBJECTPROPERTY( id, 'ExecIsDeleteTrigger') AS [Is Delete]
    8. ,OBJECTPROPERTY( id, 'ExecIsInsertTrigger') AS [Is Insert]
    9. ,OBJECTPROPERTY( id, 'ExecIsAfterTrigger') AS [Is After]
    10. ,OBJECTPROPERTY( id, 'ExecIsInsteadOfTrigger') AS [Is InsteadOf]
    11. ,OBJECTPROPERTY(id, 'ExecIsTriggerDisabled') AS [Disabled]
    12. FROM sysobjects
    13. INNER JOIN sysusers
    14. ON sysobjects.uid = sysusers.uid
    15. INNER JOIN sys.tables TAB
    16. ON sysobjects.parent_obj = TAB.object_id
    17. INNER JOIN sys.schemas SYS
    18. ON TAB.schema_id = SYS.schema_id
    19. 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
Reset Password
Fill out the form below and reset your password: