简体   繁体   English

所有(用户定义的标量)函数及其依赖关系的列表

[英]List of all (User defined scalar) functions and their dependencies

I'm trying to select a list of all the functions in the database and their dependencies. 我正在尝试选择数据库中所有功能及其依赖项的列表。

(The dependencies that would appear if I were to view the dependencies manually and select the 'Objects that depend on [function]' option.) (如果我要手动查看依赖关系并选择“依赖于[功能]的对象”选项,将会出现依赖关系。)

My main problem is getting all the dependencies to roll up into one row per function. 我的主要问题是让所有依赖项汇总到每个函数的一行中。

I've tried using stuff , but for some reason I can't get it to work in this context. 我尝试使用stuff ,但由于某种原因,我无法在这种情况下使用它。

select 
    o.name
    , stuff((select N', ' + Name from sys.objects o3 where o3.object_id = o2.object_id for xml path ('')), 1, 1, N'') as Dependencies
from sys.objects o
    left join sys.sql_expression_dependencies sed
    on object_id = referenced_id
    left join sys.objects o2
    on referencing_id = o2.object_id
where o.type='FN' 
order by o.name

Where am I going wrong? 我要去哪里错了?

This might work for you: 这可能对您有用:

SELECT
     O.Name
    ,T.Dependencies
FROM sys.Objects O
OUTER APPLY
(
    SELECT SUBSTRING(
        (
        SELECT ',' + OBJECT_NAME(D.referenced_id)
        FROM sys.SQL_Expression_Dependencies D
        WHERE D.referencing_id = O.Object_ID
        GROUP BY OBJECT_NAME(D.referenced_id)
        ORDER BY OBJECT_NAME(D.referenced_id)
        FOR XML PATH('')
        )
    ,2,4000) AS Dependencies
) T
WHERE O.Type = 'FN'
ORDER BY O.Name
;

If not, update me about what's missing and I can go from there. 如果没有,请向我更新缺少的内容,然后我可以从那里去。 Good luck! 祝好运! :) :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM