views:

50

answers:

2

I'm looking for something that would get me the same information that is displayed when I select "View Dependencies" + "Objects on which [some_table] depends"

+1  A: 

No not accurately, take a look at Do you depend on sp_depends (no pun intended) which I wrote a while back

SQLMenace
A: 

If you are using SQL Server 2008 then the following piece of SQL will show you all of the objects that depend upon the FUND table in the DBO schema.

SELECT QUOTENAME(S2.name) + N'.' + QUOTENAME(O2.name) AS ReferencingObject,

 QUOTENAME(S.name) + N'.' + QUOTENAME(O.name) AS ReferencedObject, 

SED.referenced_server_name, SED.referenced_database_name, 

SED.referenced_schema_name, SED.referenced_entity_name

FROM sys.objects AS O

INNER JOIN sys.schemas AS S ON S.schema_id=O.schema_id

INNER JOIN sys.sql_expression_dependencies SED ON SED.referenced_id=O.object_id

INNER JOIN sys.objects O2 ON O2.object_id=SED.referencing_id

INNER JOIN sys.schemas S2 ON S2.schema_id=O2.schema_id

WHERE O.name='FUND' AND S.name='DBO'

Note that the information coming back from this DMV should not be taken as being 100% accurate though - if you really need to get accurate information then either Red-Gate's SQL Dependency Tracker or ApexSQL's Doc product are fairly good.

Paul McLoughlin