5

I have a stored procedure, I want to know the name of the tables and views use in that stored procedure, can any one suggest how can I do so.

Thanks in advance.

Cade Roux
  • 88,164
  • 40
  • 182
  • 265
Zerotoinfinity
  • 6,290
  • 32
  • 130
  • 206
  • 1
    If you build and use dynamic SQL in your stored procedures, the only way to do this is to go in and read it yourself (which, trust me, really sucks). – Philip Kelley Jun 24 '10 at 13:50

3 Answers3

5

You can use sp_depends but this depends on the dependency information being up to date.

Running sp_refreshsqlmodule on all objects in the database can update this if there is any missing dependency information.

Cade Roux
  • 88,164
  • 40
  • 182
  • 265
Martin Smith
  • 438,706
  • 87
  • 741
  • 845
1
select
so.name,
sc.text
from
sysobjects so
inner join syscomments sc on so.id = sc.id
where
sc.text like '%ROLES%'-- name of the table 

Find Sp form database which is related to(using) table XXX

Pranay Rana
  • 175,020
  • 35
  • 237
  • 263