《Microsoft Sql server 2008 Internals》索引目录:《Microsoft Sql server 2008 Internals》读书笔记--目录索引
当你创建一个表时,一个或 多个行插入到若干个系统表中,以便系统能管理这些新建的表,SQL Server提供了(catalog View) 目录视图(内建于系统表的顶部),允许用户通过该视图来浏览这些内容。至少,你能在 sys.tables,sys.indexes,sys.columns分类视图中看出你创建的表等元数据。
当你定义一个或多个约束的新表, 你将会在sys.check_constraits,sys.default_constraits,sys.key_constraits或 sys.foreign_keys这几个视图中看到相关信息。
每当table被创建时, 一行记录被添加到sys.tables视图,其中包含name,Object ID和架构(Schema)ID。记住:sys.tables从sys.Objects继承所有的列,,可以从sys.columns获取更多的关于 object_id的列信息:
在SQL 2008中执行:
则可以在系统视图 中看到类似于如下的信息:
注意:如果通过AlterTable语句drop列时,column ID的序列可能发生变化,但有一个视图可以给你真实的序列值,那就是Information_Schema.columns
我们可以来察看一下这个细微的区别:
可以看到类似于下图的结果:
sys.Indexes 目录视图(Catalog View)
作为对sys.tables和sys.columns的补充,sys.indexes视图(对于每个table)返回至少一行数据。在 SQL Server 2005 及更高版本中,在目录视图中只能查看用户拥有的安全对象的元数据,或已对其为用户授予某些权限的安全对象的元数据。有关详细信息,请参阅元数据可见性配置。而 之前的版本中,sys.indexes显示的表和索引的更多的所有物理存储信息。sysindexes表的列跟踪了所有表和索引、每一个索引的根页面还有表与索引的第一个页面的空间位置等等的空间使用情况。在SQL Server 2008中,兼容性视图 sys.sysindexes包含了并不完整的信息,因为自SQL Server 2005的存储机制已经发生了变化。sys.indexes目录视图只包含一引动基本属性,比如索引是否聚集索引,是否惟一索引等。在 SQL2005/2008中为了得到更多的信息,除了查询sysindexes表,还必须使用sys.indexes加上另外两个目录视 图:sys.partitions,sys.allocation_units(或 MSDN文档中没有提及的sys.system_internals_allocation_units)
也许你可能意识到:
如果一个表有一个聚 集索引,那么表数据实际是被看作索引的一部分,因些数据行实际上是索引行。对于一个有聚焦索引的表,SQL Server在sys.Indexes中有一行记录,其中index_id为1,name为聚集索引的名称。如果一个表没有聚焦索引,那么表数据自身没有 组织,我们称这种表为堆(Heap),SQL Server同样在sys.Indexes中有一行记录,其中index_id为0,name为null。
测试如下:仍然以前面创建的EmployeeID表为例
结果如下:
建立索引后:
再执行查询如下:
每一个附加的索引在sys.indexes中对应一 行,index_Id在2-250或256-1005之间。251-255是系统 保留值,不允许使用。 呵呵。
由于每个表可以建立999个非聚集索引, 每个表在sys.indexes的行数为1-1000。。此外,一个表也可以有多个XML索引,可以在sys.xml_indexes中察看它的元数据。 这个视图继承自sys.indexes视图。
关于SQL Server目录视图的更多信息,请参看MSDN:
http://msdn.microsoft.com/zh-cn/library/ms189783.aspx
基于以下两点,SQL Server 2008可以最有效的使用一个或多个目录视图(Catalog View)来跟踪存储信息:
1、SQL Server有能力在多个分区存放表和索引,(开始吹两句啊),因此每个分区的空间使用和空间位置,必须被保持独立的跟踪。
2、表和索 引可以被存储成三种格式:Regular row data,row-Overflow data,and LOB data。后两种数据能被作为索引的 一部分,因此,每个索引必须被指定数据格式独立地进行跟踪。因此,可以说,一个表可以拥有多个索引,每个表和索引可以拥有多个分区,每个分区需要跟踪的数 据格式多达三种。
下一节将再接再励,继续学习Data Storage Metadata。枯燥啊!
邀月注:本文版权由邀月和CSDN共同所有,转载请注明出处。
助人等于自助! 3w@live.cn
分享到:
相关推荐
Microsoft SQL Server 2008 internals (PDF 高清版)
Microsoft SQL Server 2008 Internals_中文 Microsoft SQL Server 2008 Internals_中文 Microsoft SQL Server 2008 Internals_中文
Microsoft SQL Server 2008 Internals
[Microsoft Press] Microsoft SQL Server 2012 Internals (E-Book) ☆ 图书概要:☆ Dive deep inside the architecture of SQL Server 2012 Explore the core engine of Microsoft SQL Server 2012—and put ...
SQL Server 2008 Internals and Troubleshooting for DBA and developer
(1)Inside Microsoft SQL Server 2008 T-SQL Querying (2)Inside Microsoft SQL Server 2008 T-SQL Programming (3)Professional SQL Server 2008 Internals andTroubleshooting
Kalen has been working with SQL Server since 1987, specializing in query performance tuning and SQL Server internals. The Hekaton internals knowledge she provides in this book will help you migrate ...
Professional SQL Server 2012 Internals and Troubleshooting
Microsoft.SQL.Server.2008.Internals 英文版
英文版,文档版PDF,非扫描版,可复制内容。
Pro SQL Server Internals is a book for developers and database administrators, and it covers multiple SQL Server versions starting with SQL Server 2005 and going all the way up to the recently ...
由Kalen Delaney编写的微软SQL Server图书一直是同类图书中的佼佼者,是SQL Sewer开发人员、架构师和DBA的案头必备书。如今。这本新书纳入微软阵容空前的“深入解析”(Internals)系列。微软SQL Server开发团队必读...
Microsoft SQL Server 2012 Internals 英文文字版,带目录
Microsoft SQL Server 2012 Internals.pdf 英文清晰版本
Inside Microsoft SQL Server 2008: T-SQL Querying puts together all the ingredients you need to understand this declarative and set-oriented way of thinking and become a profi cient SQL programmer, ...
Kindle to PDF version. High definition with bookmarks.