Login or Sign Up to become a member!

EXPERTS, INFORMATION, IDEAS & KNOWLEDGE

Social bookmarker Add this

Find All Tables With Triggers In SQL Server

From Wiki

Jump to: navigation, search

Sometimes you want to change tables by adding columns, dropping or changing column types You want to make sure that there aren't any tables that have triggers on them so that stuff doesn't start to break after you make these changes I present two ways to accomplish that, the first way is by joining the INFORMATION_SCHEMA.TABLES view with the sysobjects system table. The second way is to do a self join on the sysobjects system table. Both of these queries will return the same result


  1. SELECT t.TABLE_NAME FROM INFORMATION_SCHEMA.TABLES t
  2. JOIN(SELECT OBJECT_NAME(o.parent_obj) AS TableName
  3. FROM sysobjects o
  4. WHERE OBJECTPROPERTY(o.[id], 'IsTrigger') = 1
  5. ) tr ON t.TABLE_NAME= tr.TableName
  6. WHERE TABLE_TYPE ='BASE TABLE'
  7. ORDER BY t.TABLE_NAME
  8.  
  9. SELECT s1.name FROM sysobjects s1
  10. JOIN sysobjects s2 ON
  11. s1.id =s2.parent_obj
  12. AND s2.xtype = 'TR'
  13. WHERE s1.xtype = 'U'
  14. ORDER BY s1.name


Contributed by: --SQLDenis 16:17, 9 June 2008 (GMT)


Part of SQL Server Admin Hacks

396 Rating: 4.5/5 (2 votes cast)