为什么有些系统表被判定为“假表”?使用“TableIsFake”对象属性?
我今天查看了 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
是什么使得 sysfiles
、sysforeignkeys< /code>、
sysindexkeys
、sysmembers
、sysprotects
系统表“假”?或者换句话说,它们“由 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
假表是一种特殊的“内存中”结构,没有磁盘持久性。 SQL Server 根据需要创建它。
最好的例子是 sysprocesses。
恕我直言:关键是“磁盘上的持久性”:
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":
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