SQLUSA.com
SQL SERVER 2008 GRAND SLAM
FREE TRIAL  CLICK HERE TO ORDER  SEARCH
SQL JOBS SQL Server Training Scripts JOB BANK
  SQL Server 2008 Training Scripts  
  SQL Server 2005 Training Scripts  
News SQL Server Articles SQL Format

How to list all triggers with stored procedures?

Execute the following Microsoft SQL Server T-SQL scripts in SSMS Query Editor for listing of trigger definitions which apply stored procedures (stored procedure name found in definition text).

 

-- List all triggers definition which use one or more stored procedure

-- System views: sys.triggers, sys.procedures

USE AdventureWorks2008;

SELECT DISTINCT Sproc=p.name, TrgText= OBJECT_DEFINITION(t.object_id)

FROM sys.triggers t

  INNER JOIN  sys.procedures p

    ON PATINDEX('%'+p.name+'%', OBJECT_DEFINITION(t.object_id)) > 0

  WHERE p.TYPE='P'

ORDER BY TrgText, p.Name

/* uspPrintError  CREATE TRIGGER [Production].[iWorkOrder] ON [Production].[WorkOrder]  

AFTER INSERT AS   BEGIN  DECLARE @Count int;  SET @Count = @@ROWCOUNT; 

IF @Count = 0   RETURN;  SET NOCOUNT ON;  BEGIN TRY 

INSERT INTO [Production].[TransactionHistory](  [ProductID]  ,

[ReferenceOrderID]  ,[TransactionType]  ,[TransactionDate]  ,[Quantity]  ,

[ActualCost])  SELECT   inserted.[ProductID]  ,inserted.[WorkOrderID]  ,'W'  ,

GETDATE()  ,inserted.[OrderQty]  ,0  FROM inserted;  END TRY 

BEGIN CATCH  EXECUTE [dbo].[uspPrintError];  IF @@TRANCOUNT > 0 

BEGIN  ROLLBACK TRANSACTION;  END  EXECUTE [dbo].[uspLogError]; 

END CATCH;  END; 

......

*/

------------

Order SQL 2008 GRAND SLAM Today!
SQLUSA.com Home Page
SQL Server Training at www.sqlusa.com.
SQL Server 2008 Video Training at www.sqlusa.com.
SQL Server 2005 Training Videos at www.sqlusa.com.
Microsoft SQL Server 2000 Training Videos at www.sqlusa.com.

FREE SQL & Business Intelligence / OLAP Short Videos on YOUTUBE.com

Microsoft Community Contributor 2011
Invest in Your SUCCESS!

Search SQLUSA FREE SQL Server Articles & FREE T-SQL Scripts


Copyright 2005-2011, SMI Corp. All Rights Reserved.

SQL Server 2012 is a program product of Microsoft Corporation.
SQL Server 2008 is a program product of Microsoft Corporation.
SQL Server 2005 is a program product of Microsoft Corporation.
SQL Server 2000 is a program product of Microsoft Corporation.