Sql Server: all object dependencies

前端 未结 3 2072
再見小時候
再見小時候 2021-01-16 08:24

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

3条回答
  •  一向
    一向 (楼主)
    2021-01-16 08:52

    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
    

提交回复
热议问题