tags:

views:

112

answers:

3

Hi,

Is there any place where I can find all possible object type dependencies in Sql Server?

What I mean by "object dependency" is a list of object that one object can depend on. For example, TABLE can depend on SCHEMA, TYPE, TABLE, FUNCTION, etc.

A: 

For actual objects (what objects does table 'foo' depend on):

sys.sql_dependencies

Is mostly accurate. There is also the SMO helper, DependencyWalker.

As a general type question (ie. what type of objects can a table depend on), you just need to go through the spec on MSDN for each object CREATE/ALTER statement and read carefully everything.

Remus Rusanu
I am interested in the dependencies between all object in general, not about the dependencies in one certain database/server.For example, I want a list of ALL OBJECTS that a TABLE can depend on, etc.
Gjorgji
A: 

Aside from dynamic SQL, technically, SQL Server does keep track of dependencies. However, until SQL Server 2008, its tracking was not reliable because it only updated dependencies if all dependent entities existed at time of creation. SQL Server 2008 significantly improved dependency tracking.

In SQL Server 2000 and 2005, you can query against sys.sql_dependencies to get a list of dependencies.

In SQL Server 2008, you should use sys.sql_expression_dependencies See sys.sql_expression_dependencies for more.

EDIT I think I may have misinterpreted your question. It sounds like you are looking for a list of object types on which a TABLE type object can depend. Directly or indirectly, it would be any object type in the system. If we only want "direct" dependencies, then it depends on what is meant by "direct". For example, does a trigger that references a view count as a direct dependency of the trigger table to the view?

EDIT As far as I know, there is no enumerated list of all possible dependencies between types. The best that you could achieve is to analyze the types that do depend on other types in a given database using something like:

Select DependentObj.Type, ReferencedObj.Type
from sys.sql_dependencies As D
    Join sys.sysobjects As ReferencedObj
        On ReferencedObj.id = D.referenced_major_id 
    Join sys.sysobjects As DependentObj
        On DependentObj.id = D.object_id 
Group By DependentObj.Type, ReferencedObj.Type
Thomas
I am interested in the dependencies between all object in general, not about the dependencies in one certain database/server. For example, I want a list of ALL OBJECTS that a TABLE can depend on, etc.
Gjorgji
@Gjorgji - I'm not sure I understand. Using the catalog view mentioned, you can find all objects that depend on a given table or all objects on which the given table depends.
Thomas
@Gjorgji - However, it should be clear that there is no means to determine what objects outside the database depend on a given table.
Thomas
@Gjorgji - Is it that you are looking for a list of object *types* on which an object of type "table" can depend?
Thomas
@Thomas: That is exactly what I am looking for. I need all object types with all dependencies.Thanks,Gjorgji.
Gjorgji
@Gjorgji - First, there is no list of which I'm aware that enumerates those relationships. Second, for tables at least, they can directly or indirectly depend on any object type in the system. Thus, I do not think there is a simple means to answer that other than to use sys.sql_dependencies to get a list of unique object types on which one or more tables depend.
Thomas
A: 

A persisted computed column in a table could depend on a user defined function.

A non-deterministic user-defined function can depend on a table.

A constraint could cause a table to depend on a table.

ad nauseum.

You could pick any pair of object types and we might be able to come up with a dependency.

There are obviously some restrictions in the various SQL Server features, but I'm not aware of any comprehensive matrix of all possible allowed and disallowed dependencies.

Cade Roux