Wednesday, 7 October 2020

SQL SERVER – Find Stored Procedure, View and Function Related to Table in Database

In this article, I am explaining, How to find Stored Procedure, View, and Function list Related to a particular Table in SQL Database. Below query, help to find that

SELECT DISTINCT b.nameb.xtype

FROM syscomments a

INNER JOIN sysobjects b ON a.id b.id
WHERE a.TEXT LIKE '%tablename%'

If we want to search table only in the stored procedure then we can use the below query

SELECT Name

FROM sys.procedures

WHERE OBJECT_DEFINITION(OBJECT_ID) LIKE '%tablename%'