Get List of Tables associated with an SP

Hello Guys,

Often when we go through an SP which has been wriiten by someone else,

we require the table’s used in the SP.

Following script will return the list of tables used in an SP

by taking SP name as parameter.


select (select name
        from   sys.schemas
        where  schema_id = t.schema_id)  +’.’+name
from   sys.tables as t
where  t.object_id in (select depid
                       from   sys.sysdepends
                       where  id in (select s.object_id
                                     from   sys.procedures as s
                                     where  name like ‘%Employee Sales by Country%’));



Hope this helps…..


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s