Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Write a query that returns the dependencies of an object

I'm looking for exactly what Management Studio shows with the "View Dependencies" menu.

  1. Management Studio connected to SQL Server 2008
  2. Right click on an object and choose "View Dependencies"
  3. Now you can navigate through the dependencies back and forth.

How do I get the same information programmatically? (an SQL query?)

like image 288
Nestor Avatar asked Dec 29 '22 08:12

Nestor


1 Answers

Here is another simpler way:

  SELECT DISTINCT
    O.ID ,
    O.Name AS TableName ,
    O.xtype
  FROM
    sysObjects O ( NOLOCK )
  INNER JOIN sysComments C ( NOLOCK ) ON O.ID = C.ID
  WHERE
    C.text LIKE '%<schema_name.function_name>%'
  ORDER BY
    XType ,
    TableName
Before you run the following query, replace <schema_name.function_name> with a valid name
like image 105
Scott and the Dev Team Avatar answered Jan 29 '23 20:01

Scott and the Dev Team