Thursday, February 18, 2016

Listing Dependencies of Stored Procedure in MS SQL

When you want to check the dependencies of a stored procedure as in which tables are being used,
you can use the below query

SELECT DISTINCT p.name AS proc_name, t.name AS table_name
FROM sys.sql_dependencies d 

INNER JOIN sys.tables     t ON t.object_id = d.referenced_major_id
INNER JOIN sys.procedures p ON p.object_id = d.object_id

ORDER BY proc_name, table_name

Below is the result on execution of the above query on the Northwind Database


You can also try

sp_depends Procedure_Name

No comments: