为什么有些系统表被判定为“假表”?使用“TableIsFake”对象属性?

发布于 2024-11-05 12:02:37 字数 1436 浏览 0 评论 0原文

我今天查看了 ObjectProperty 列表,发现了 TableIsFake 属性。这个名字让我很有趣,所以我查看了它检查的内容:

该表不是真实的。它由 SQL Server 根据需要在内部具体化。

这究竟意味着什么?例如,当我运行以下查询时:

SELECT [name], xtype
FROM dbo.sysobjects
WHERE OBJECTPROPERTY(object_id([name]), N'TableIsFake') = 1 
ORDER BY [name]

我得到以下结果:

name           xtype
-------------- -----
sysfiles       S 
sysforeignkeys S 
sysindexkeys   S 
sysmembers     S 
sysprotects    S 

但如果我查询数据库中的系统表:

SELECT [name], xtype
FROM dbo.sysobjects
WHERE xtype = 'S'
ORDER BY [name]

我得到以下系统表:

name                xtype
------------------- -----
syscolumns          S 
syscomments         S 
sysdepends          S 
sysfilegroups       S 
sysfiles            S 
sysfiles1           S 
sysforeignkeys      S 
sysfulltextcatalogs S 
sysfulltextnotify   S 
sysindexes          S 
sysindexkeys        S 
sysmembers          S 
sysobjects          S 
syspermissions      S 
sysproperties       S 
sysprotects         S 
sysreferences       S 
systypes            S 
sysusers            S 

是什么使得 sysfilessysforeignkeys< /code>、sysindexkeyssysmemberssysprotects 系统表“假”?或者换句话说,它们“由 SQL Server 根据需要在内部具体化”是什么意思?这是否意味着它们仅在进程需要时创建,或者如果我调用类似 SELECT * FROM sysfiles 的内容?

I was looking over the ObjectProperty list today and came across the property TableIsFake. The name amused me, so I looked at what it checks:

The table is not real. It is materialized internally on demand by SQL Server.

What exactly does this mean? For example, when I run the following query:

SELECT [name], xtype
FROM dbo.sysobjects
WHERE OBJECTPROPERTY(object_id([name]), N'TableIsFake') = 1 
ORDER BY [name]

I get the following results:

name           xtype
-------------- -----
sysfiles       S 
sysforeignkeys S 
sysindexkeys   S 
sysmembers     S 
sysprotects    S 

But if I query the database for system tables:

SELECT [name], xtype
FROM dbo.sysobjects
WHERE xtype = 'S'
ORDER BY [name]

I get the following system tables:

name                xtype
------------------- -----
syscolumns          S 
syscomments         S 
sysdepends          S 
sysfilegroups       S 
sysfiles            S 
sysfiles1           S 
sysforeignkeys      S 
sysfulltextcatalogs S 
sysfulltextnotify   S 
sysindexes          S 
sysindexkeys        S 
sysmembers          S 
sysobjects          S 
syspermissions      S 
sysproperties       S 
sysprotects         S 
sysreferences       S 
systypes            S 
sysusers            S 

What makes the sysfiles, sysforeignkeys, sysindexkeys, sysmembers, sysprotects system tables "fake"? Or put another way, what does it mean that they are "materialized internally on demand by SQL Server"? Does that mean they are only created when a process needs it, or if I call something like SELECT * FROM sysfiles?

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

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

发布评论

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

评论(2

做个少女永远怀春 2024-11-12 12:02:37

假表是一种特殊的“内存中”结构,没有磁盘持久性。 SQL Server 根据需要创建它。

最好的例子是 sysprocesses。

恕我直言:关键是“磁盘上的持久性”:

  • sysusers 或 sysxlogins (例如)分别是每个 db/master 中的真实表,并且在备份/恢复中存活
  • sysprocesses 或 sysfiles 将无法在备份/恢复中存活,因为没有任何内容可写入或读取到磁盘

A fake table is a special "in memory" structure with no on-disk persistence. SQL Server creates it on demand.

The best example is sysprocesses.

IMHO: the key is "on disk persistence":

  • sysusers or sysxlogins (for example) are real tables in each db/master respectively and survive backups/restores
  • sysprocesses or sysfiles will not survive a backup/restore because there is nothing to write or read to disk
渔村楼浪 2024-11-12 12:02:37

sysfiles 表实际上是一个视图,其创建方式是为了向后兼容
请参阅将系统表映射到系统视图以了解您应该使用

什么您应该使用 sys.database_files 而不是 sysfiles

The sysfiles table is really a view and is created like that for backwards compatibility
See Mapping System Tables to System Views to see what you should be using

So instead of sysfiles, you should use sys.database_files

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