gpt4 book ai didi

sql - 如何编写脚本来查找 SQL Server 数据库对象(如 storedproc 和 View )中使用的数据库?

转载 作者:搜寻专家 更新时间:2023-10-30 23:14:46 26 4
gpt4 key购买 nike

我们在 SQL Server 2012 中的一个数据库(数据库 A)即将停用。我正在分析数据库 B 中使用数据库 A 作为数据源的所有 View 和 StoredProcs。如何编写查询来检索此信息。谢谢

最佳答案

我使用以下方法在 SQL Server 2008 中获取对象及其依赖项:

select *
from (select referenced_database_name, o.name as ViewName, ed.referenced_entity_name as TableName
from sys.sql_expression_dependencies ed join
sys.objects o
on ed.referencing_id = o.object_id
where referenced_database_name is not null
) vdep

您可以添加过滤器以过滤掉您感兴趣或不感兴趣的数据库:

where referenced_database_name = 'A'

关于sql - 如何编写脚本来查找 SQL Server 数据库对象(如 storedproc 和 View )中使用的数据库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15791384/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com