Get table names used in Stored Procedure


Get all tables used in Stored Procedure.
Below is the simple query to get name of all the tables used in the stored procedure.

DECLARE @spName VARCHAR(200) = 'storedprocedure_name'
DECLARE @tbl AS TABLE (AutoId INT IDENTITY(1,1), SpText TEXT)

INSERT INTO @tbl
exec sp_helptext @spName

SELECT DISTINCT b.TABLE_NAME FROM @tbl a, INFORMATION_SCHEMA.TABLES b
WHERE a.SpText LIKE '%' + b.TABLE_NAME + '%'


Comments

Popular posts from this blog

Get Query String Values With Javascript

Change Css Class of li in ul onclick

Change Text Color with Javascript