为什么系统视图会复制到用户数据库?

发布于 2024-09-25 11:41:09 字数 1033 浏览 1 评论 0原文

为什么 SQL Server 将数百个系统视图从模型数据库复制到每个用户定义的数据库中,而不是将它们集中起来(例如,因为它保留服务器对象)并在要求/需要时在特定数据库的特定上下文中使用它们?

它们(例如,系统视图的定义/脚本)在数据库之间不是通用的吗?


更新:

我仍然无法得到它:
1)
为了在另一个数据库的上下文中执行视图,无需将视图定义复制到每个数据库中(只需提取视图定义并在特定数据库的上下文中执行)。
那么,为什么要复制副本呢?
2)
然后,我仍然很困惑什么存储在哪里?

[1] (BOL2005[1a]-2008R2[1b]) 指出:

“在 SQL Server 中,系统对象不再存储在主数据库中;而是存储在资源数据库中

另外,我想了解为什么 SSMS 允许编写服务器对象脚本(例如.,在服务器对象下的对象资源管理器中右键单击 --> syspolicy_server_trigger 上的触发器 --> 脚本服务器触发器为...---> ),而例如,系统视图则没有这种可能性。

是什么让他们与众不同?它们分别存储在哪里?


被引用:
[1]主数据库
[1a]
(SQL Server 2008 R2 联机丛书)
http://msdn.microsoft.com/en-us/library/ms187837.aspx
[1b]
(SQL Server 2005 联机丛书)
http://msdn.microsoft.com/en-我们/库/ms187837(v=SQL.90).aspx

Why has SQL Server to duplicate a hundred of system views from model database into each user-defined database instead of keeping them centralised (for example, as it keeps server objects) and using them in specific context of specific database when asked/needed?

Aren't they (for example, definitions/script of a system view) common between databases?


Update:

I still could not get it:
1)
In order to execute a view in context of another database there is no need to copy view definitions into each database (just extract view def and execute in context of specific database).
So, why to multiplicate copies?
2)
Then, I am still confused what is stored where?

[1] (BOL2005[1a]-2008R2[1b]) tells that:

"In SQL Server, system objects are no longer stored in the master database; instead, they are stored in the Resource database"

Also, I would like to understand why SSMS permits to script server objects (for ex., right-click in Object Explorer under Server Objects --> Triggers on syspolicy_server_trigger --> Script Server Trigger as...---> ) while, for ex., system views do not have such possibility.

What does make them different? Where are they, resp., stored?


Cited:
[1] master Database
[1a]
(SQL Server 2008 R2 Books Online)
http://msdn.microsoft.com/en-us/library/ms187837.aspx
[1b]
(SQL Server 2005 Books Online)
http://msdn.microsoft.com/en-us/library/ms187837(v=SQL.90).aspx

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

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

发布评论

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

评论(1

善良天后 2024-10-02 11:41:09

它们不是重复的。

  • sys.objects 和 sys.database_principals 被存储,因为它们是特定于数据库的
  • sys.server_triggers 或 sys.server_permissions 仅存在于主数据库中的服务器级别

SQL Server 根据需要将 sys 架构正确解析为数据库或服务器:

USE MyDB
GO
SELECT * FROM sys.server_permissions   --   <. always from master db 

这么简单,在日常实践中没有用处......

编辑:在 Martin Smith 发表评论后,来自 MSDN

They aren't duplicated.

  • sys.objects and sys.database_principals are stored because they are database specific
  • sys.server_triggers or sys.server_permissions only exist at the server level in master db

SQL Server resolves the sys schema correctly to the database or server as required:

USE MyDB
GO
SELECT * FROM sys.server_permissions   --   <. always from master db 

It is that simple and of no use on a practical day to day level...

Edit: After Martin Smith's comment, from MSDN

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