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
  • 85,870
  • 40
  • 177
  • 264
Zerotoinfinity
  • 5,952
  • 31
  • 126
  • 200
  • 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
  • 85,870
  • 40
  • 177
  • 264
Martin Smith
  • 419,657
  • 83
  • 708
  • 800
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
  • 170,430
  • 35
  • 234
  • 261