与视图相关的数据库对象 - sql server 2005

发布于 2024-10-16 17:25:55 字数 198 浏览 1 评论 0原文

如何知道有多少数据库表、视图或附加到 sql server 2005 数据库中的视图的任何其他对象。 我尝试使用 Sp_Depends,但令人惊讶的是它没有显示使用它的 SP 名称。

当我运行语句 Sp_depends vw_MyViewName 时。

我只获取在 vw_MyViewName 中使用的表和列的名称。我需要知道与此视图相关的其他对象。

How to know that how many database tables, views or any other object attached to a view in sql server 2005 database.
I tried with Sp_Depends, but amazingly it is not showing the SP name in which it is getting used.

When I run the statement Sp_depends vw_MyViewName.

I am only getting the name of the tables and columns which I have used inside the vw_MyViewName. I need to know other objects related to this view.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

疯狂的代价 2024-10-23 17:25:55

在 SQL Server 2005 中,如果您以错误的顺序创建对象,就会发生这种情况。

您将收到一条警告消息,指出无法为缺失的对象添加依赖关系信息,但仍会创建该对象。

您可以在数据库中的所有对象上运行 sp_refreshsqlmodule 来重新创建此类缺失的依赖关系信息(执行此操作的示例脚本位于此处 如何查找所有插入、更新或删除记录的存储过程?)

In SQL Server 2005 this happens if you create the objects in the wrong order.

You will get a warning message that the dependency information could not be added for a missing object but the object will still be created

You can run sp_refreshsqlmodule on all objects in your database to recreate such missing dependency information (an example script to do that is here How do I find all stored procedures that insert, update, or delete records?)

聽兲甴掵 2024-10-23 17:25:55

在引入 sys.sql_expression_dependencies 之前 (SQL Server 2008),您需要查询 sys.sql_modules

SELECT OBJECT_NAME(object_id)
FROM sys.sql_modules
WHERE definition LIKE '%MyTable%'

就我个人而言,我会使用 WITH SCHEMABINDING 确保依赖关系必须存在

Until sys.sql_expression_dependencies was introduced (SQL Server 2008), you need query sys.sql_modules

SELECT OBJECT_NAME(object_id)
FROM sys.sql_modules
WHERE definition LIKE '%MyTable%'

Personally, I'd use WITH SCHEMABINDING to ensure dependencies must exist

七色彩虹 2024-10-23 17:25:55

据我所知,确定 SQL Server 数据库中的对象依赖关系的唯一完全可靠的方法是将架构加载到 Visual Studio Database Edition (DBPro) 中并检查那里的依赖关系。我发现这是万无一失的,与 SQL Server 跟踪依赖关系的方式不同。

我不一定会因此责怪 SQL Server。我认为它从未声称能够 100% 准确地跟踪依赖关系,主要是因为它绑定对象的方式。

The only completely reliable way I know of to determine object dependencies in a SQL Server database is to load your schema into Visual Studio Database Edition (DBPro) and examine the dependencies there. I have found this to be foolproof, unlike the way SQL Server tracks dependencies.

I wouldn't necessarily fault SQL Server for this. I don't think it ever made the claim that it was able to track dependencies with 100% accuracy, mostly because of the way it binds objects.

夏の忆 2024-10-23 17:25:55

在 SQL Server Management Studio 的“对象资源管理器”面板中,右键单击要检查的对象(存储过程、表、视图...),然后单击“显示依赖关系”。

出现的窗口将显示依赖对象和“依赖”对象,只需在两个单选按钮之间切换即可;)

如果您想手动执行此操作,则需要在 sys.sql_dependency 系统视图上构建查询。 这里是说明的链接一些示例

请注意,将创建依赖于不存在的表、视图和其他对象的存储过程,但它们不仅明显不起作用,而且不会添加依赖项信息,直到创建所有“依赖”对象,并且SP被重新创建!

In SQL Server Management Studio, in Object Explorer panel, right click on the object you want to inspect (stored procedure, table, view, ...) and click on "Show Dependencies".

The window that appear, will show you both dependant and "depended" objects, simply by switching between two radio button ;)

If you want to do it by hand, you need to build a query over the sys.sql_dependencies system view. Here a link to the description with some examples

Beware that stored procedures that depends on nonexistants tables, view, and other objects, will be created, but not only they obviously doesn't work, but dependency informations will not be added, until all "depended" objects are created, AND the SP is REcreated!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文