List out stored procedure use SQL table - Table use under stored procedure

In SQL Server if you want to find list of tables used by store procedures you can use below command.


EXEC sp_depends @objname = '<Stored Procedure Name>'

But let say you write dynamics query within SPs above command will eliminate those tables which are used in dynamic query. Below are sample query will return 100% accurate result.

Requirement :

List of Stored Procedures which are using those tables their name are started with PP.

Use <[Database Name]>


SELECT
     P.NAME,
     T.NAME
FROM SYSOBJECTS
     JOIN syscomments C ON P.ID = C.ID
     JOIN sysobjects T ON T.Name like 'PP%' AND T.[TYPE] = 'U' AND C.[TEXT] like('%'+T.Name+'%')
WHERE P.[TYPE] = 'P'
ORDER BY 1

Above query will work in SQL server 2000, 2005 & 2008 version

Comments

Popular posts from this blog

SQL Server - Recursive Conditional Calculation.

CRM Report (SSRS) - Multi value parameter dropdown - horizontal scrollbar issue.

Microsoft Dynamic CRM 2016 / 2015 / 2013 / 2011 SOAP XML