CREATE DATABASE foo; GO USE foo; GO CREATE TABLE t1 (c1 INT IDENTITY, c2 CHAR (1000) DEFAULT 'a'); CREATE CLUSTERED INDEX t1c1 ON t1 (c1); GO SET NOCOUNT ON; GO INSERT INTO t1 DEFAULT VALUES; GO 10000
接下来设置填充因子为0并重建索引
复制代码 代码如下:
SELECT [fill_factor] FROM sys.indexes WHERE NAME = 't1c1' AND [object_id] = OBJECT_ID ('t1'); GO ALTER INDEX t1c1 ON t1 REBUILD WITH (FILLFACTOR = 100); GO
上面的代码执行后,通过查看既定页中的m_freeCnt列的值,也就是页中可用空间的值:
复制代码 代码如下:
EXEC sp_allocationMetadata 't1'; GO DBCC TRACEON (3604); DBCC PAGE (foo, 1, 164, 3); -- the root page, from the SP output GO DBCC PAGE (foo, 1, 162, 1); -- the page ID in the DBCC PAGE output above GO
通过上面代码可以看到值为10,也就是说业内不存在保留空间。这时一个误区,有关上面sp_allocationMetadata的实现细节请看这篇博文:this blog post。