How to list sql server table dependencies using T-SQL?

You can always use SQL Server Management Studio, just right click on a table in object explorer and select View Dependencies.

View Dependencies

However this way doesn't give you ability to copy dependencies to clipboard or any other way to export dependencies list. Luckily you can find the same data using SysObjects and SysDepends tables. Here is a quick T-SQL snippet that you might want to use for this purpose.

SELECT DISTINCT dobj.name,dobj.type
FROM SysObjects obj INNER JOIN 
SysDepends d ON obj.id = d.depid INNER JOIN 
SysObjects dobj ON d.id = dobj.id
WHERE obj.name = 'WorkOrder' ORDER BY dobj.type,dobj.name

Posted on Sunday, February 19, 2012 by | Comments (4) | Add Comment

Comments

Gravatar

Re: How to list sql server table dependencies using T-SQL?

Nice blog.

Posted on 7/10/2012 4:53:57 AM by Neelam #
Gravatar

Re: How to list sql server table dependencies using T-SQL?

Or get SQL Negotiator Pro from www.aphilen.com
Graphically draws dependencies for tables and stored procedures etc

Posted on 8/28/2013 11:01:53 PM by Sameer #
Gravatar

Re: How to list sql server table dependencies using T-SQL?

great post, thanks for the tool recommendation Neelam
worked a treat

Posted on 9/27/2013 8:55:55 PM by taylor #
Gravatar

Re: How to list sql server table dependencies using T-SQL?

Great app Neelam. Thanx for rec :-)

Posted on 11/4/2013 1:24:00 AM by Gavin #

New Comment

Your Name:
Email (for internal use only):
Comment:
 
Code above:

Categories

Recent Tweets

  • Simon Ince's Blog: Hierarchies with HierarchyID in SQL 2008 http://t.co/xSDwiF6rRS.
  • Visual Studio 2010 WAS painfully slow - CodeProject http://t.co/Usba1x6CZy

Valid HTML5