2016-04-03 45 views
1

我很难理解为什么我在分析行结构时在以下内容中获取多个条目。分析SQL Server中的数据结构

首先,我设置了两个表格。

我正在挖掘行/页结构使用下面的查询。

CREATE TABLE [Table1] 
(
    [Column1] INT IDENTITY PRIMARY KEY, 
    [Column2] VARCHAR (100), 
    [Column3] VARCHAR (20) 
) 

CREATE TABLE [Table2] 
(
    [Column1] INT IDENTITY 
     FOREIGN KEY REFERENCES [Table1]([Column1]), 
    [Column4] VARCHAR (1000) 
) 

然后,我用下面

BEGIN TRANSACTION 

INSERT INTO [Table1] ([Column2], [Column3]) 
VALUES (REPLICATE ('2', 50), REPLICATE('3', 20)) 

INSERT INTO [Table2] ([Column4]) 
VALUES (REPLICATE ('4', 1000)) 
GO 1000000 

COMMIT TRANSACTION 

然后,使用下面的查询插入一个百万行,我试试,看多少页组成表。

SELECT 
    [alloc_unit_type_desc] AS [Data Structure], 
    [page_count] AS [pages], 
    [record_count] AS [Rows] 
FROM 
    SYS.dm_db_index_physical_stats (DB_id(), OBJECT_ID (N'Table1'), NULL, NULL, N'detailed') 

这是我的问题:这些其他41页来自哪里?当他们显然不包含相同的数据?我在选择表上也看不到它们。

+1

之间是什么40个中间页面查询的结果? –

回答

4

如果添加index_level到您的查询,你会看到

SELECT [alloc_unit_type_desc] AS [Data Structure], 
     [page_count]   AS [pages], 
     [record_count]   AS [Rows], 
     index_level 
FROM sys.dm_db_index_physical_stats (DB_id(), 
       OBJECT_ID (N'Table1'), NULL, NULL, N'detailed') 

enter image description here

表与主键生成。这将默认为聚簇索引。所述B-tree索引来支持这种具有单个根页面和根,并在水平的11112叶级页0

(聚簇索引from here的结构)

enter link description here