How to find if Table is used in Stored Procedure in SQL Server
One drawback of using sp depends is
that it won't display tables or views that aren't in the current database. This
information may be inaccurate if you have used objects from other databases.
--By using sp_depends, You can provide Stored Procedure Name
or View name as parameter
EXEC sp_depends '[dbo].[TableName]'
Second Method:
--Get Information from sys.sysdepends
SELECT DISTINCT OBJECT_NAME(SD.id) AS StoredProcedureNameName,
OB.name AS TableOrViewName
FROM sys.sysdepends SDINNER JOIN sys.sysobjects O
ON SD.id=O.id
INNER JOIN sys.sysobjects OB
ON SD.depid=OB.id
AND O.xtype='P'
Third Method:
--Use sys.all_sql_modules system view to get information if
table is used
--in a Stored Procedure
SELECT OBJECT_NAME(OBJECT_ID),definition
FROM sys.all_sql_modules
WHERE definition LIKE '%vw_Employee%'
0 Comments