SQL Server Dependencies

前端 未结 8 1580
说谎
说谎 2020-11-28 10:00

Is there an easy way to chase down table/stored procedure/function dependencies in SQL Server 2005+? I\'ve inherited a giant application with lots of tables and even more s

相关标签:
8条回答
  • 2020-11-28 10:37

    Here is a list of options if you're low on the budget:

    http://www.mssqltips.com/tip.asp?tip=1294

    You could also run a trace and see what management studio is actually doing when you click 'view dependencies'. Grab that code and see if you can modify it for your own use. This is a good technique for figuring out how to automate various things that you normally do through the UI.

    0 讨论(0)
  • 2020-11-28 10:38

    I have found this solution and its great.

    SELECT referencing_schema_name, referencing_entity_name,
    referencing_id, referencing_class_desc, is_caller_dependent
    FROM sys.dm_sql_referencing_entities ('dbo.udf_func', 'OBJECT');
    
    0 讨论(0)
  • 2020-11-28 10:48

    Red Gate has a pretty useful tool called SQL Dependency Tracker. We've successfully used it for the type of results you're wishing to obtain.

    0 讨论(0)
  • 2020-11-28 10:55

    The system table that attempt to keep track of dependencies is usually wrong, so any answer you get from that, you will have to re-confirm by other means, so why bother with it?

    Commercial products exist, such as Redgate SQL Dependency Tracker.

    A poor developer like myself, I use SQL Digger, which is free. By searching the DDL for an object name, you usually can find what first degree dependencies there are for an object in question.

    The next level of dependency tracing is to trace what C# or VB.NET net objects depend on an object in SQL, but AFAIK, tools don't exist for that outside of global search.

    0 讨论(0)
  • 2020-11-28 10:56

    Hopefully I'm not too late with this:

    If your SQL Login has access to the sys schema in a particular database, you can use the sys.dependencies view to find all of an object's dependencies in one shot:

    SELECT o.name, o.type_desc, p.name, p.type_desc
    FROM sys.sql_dependencies d
    INNER JOIN sys.objects o
        ON d.object_id = o.object_id
    INNER JOIN sys.objects p
        ON d.referenced_major_id = p.object_id
    

    Using this as a starting point you could probably build a decent tool to create a dependency tree. There are also type specific views (e.g. sys.columns) that give more in depth information regarding each specific database object type; these could be used to provide contextual information on an object if necessary.

    0 讨论(0)
  • 2020-11-28 10:57

    try this productivity tool http://sqlhopper.weebly.com/ It's cool

    0 讨论(0)
提交回复
热议问题