Archive | December, 2011

Query for Geting dependent tables of a stored procedure

17 Dec

In MS SQL Server 2008, you may get the table names dependents by a stored procedure using the following query


,(SELECT name FROM sys.schemas WHERE schema_id=t.schema_id) AS schemaName

FROM  sys.tables t

WHERE  t.object_id in (SELECT depid

FROM sys.sysdepends

WHERE id In (SELECT s.object_id FROM sys.procedures s WHERE name=’SPName‘))

SPName  is the name of  stored procedure.

Th output will be the table name and its schema. Happy querying .. 🙂