日期:2014-05-17 浏览次数:20474 次
/*----------------------------------------------------------------------
*auther:Poofly
*date:2010.3.14
*VERSION:
Microsoft SQL Server 2008 (RTM) - 10.0.1600.22 (Intel X86)
Jul 9 2008 14:43:34
Copyright (c) 1988-2008 Microsoft Corporation
Enterprise Evaluation Edition on Windows NT 6.1 <X86> (Build 7600: )
*转载请注明出处
*更多精彩内容,请进http://blog.csdn.net/feixianxxx
------------------------------------------------------------------------*/
--建表(表源来自技术内幕)
GO
CREATE TABLE NC_JNodes (
id int NOT NULL ,
str1 char (5) NOT NULL ,
str2 varchar (10) NULL
);
GO
--在str2上建立唯一性的聚集索引,在str1上建立具有唯一性的非聚集索引
CREATE UNIQUE CLUSTERED INDEX idxcl_str2 on NC_JNodes (str2);
CREATE UNIQUE INDEX idxNC ON NC_JNodes (str1);
GO
--插入数据
DECLARE @i int;
SET @i = 1240;
WHILE @i < 13000 BEGIN
INSERT INTO NC_JNodes
SELECT @i, cast(@i AS char),
cast(cast(@i * rand() AS int) as char); --打乱了str1的排序
SET @i = @i + 1;
END;
GO
--查看页面分布和页号文件号
TRUNCATE TABLE sp_table_pages;
INSERT INTO sp_table_pages
EXEC ('dbcc ind (poofly,NC_JNodes, -1)');
SELECT PageFID, PagePID, IndexID, IndexLevel, PageType
FROM sp_table_pages
WHERE IndexLevel >= 0;
/*
PageFID PagePID IndexID IndexLevel PageType
------- ----------- ------- ---------- --------
5 967 1 0 1 --该条是聚集索引的叶级别的数据页面
5 969 2 0 2 --该条是非聚集索引的叶级别的索引页面
5 971 1 1 2 --该条是聚集索引的子结点的索引页面
5