Thursday 14 June 2012

Find all Views and SP which depends on a Table


     If you wish to Select all the Views and SP's which depends on a table then we can find it from the sys.sysdepends table. It contains all the depedencies of all the tables.

    Let's say you have a table 'MstEmployee' and you wish to find all the Views and SP's in which this table is referred, then write below query :


SELECT  DISTINCT OBJECT_NAME(DP.ID) ObjName
FROM    sys.sysdepends DP
        INNER JOIN  sys.sysobjects OB
        ON DP.DepID = OB.ID
WHERE   OB.NAME = 'MstEmployee'

---- Output --------
ObjName
USP_NewEmployees
USP_Employee_Insert
USP_GetEmployeeDetails
USP_CheckEmployeeExistance
VW_CorporateEmployees





Reference: Govind Badkur(http://govindbadkur.blogspot.com)

No comments:

Post a Comment