利用DBCC PAGE查看SQL Server中的表和索引数据 - Uest
按 Ctrl+C 复制代码
按 Ctrl+C 复制代码
一、查看表的数据
在系统表sysindexes 的列 first中保存有 filenum,pagenum 的信息(当indid为0或者1), 列first 的数据类型为
binary(6), 它是以16进制的形式储的,需要进行转换. 在16进制中,每两个进制数字表示一个字节,并且是逆序排列
的. 转换完成,其中前2组数表示该表所在的文件编号; 后4组表示该表所在的页码.
根据sysindexes 中的列first返回表所在的filenum 、pagenum
1 declare @first binary(6)
2 select @first=first from sysindexes where id=object_id('fanr_city') and indid in(0,1)
3 declare @PageNum int
4 select @PageNum=convert(int,substring(@first,4,1)+substring(@first,3,1)+
5 substring(@first,2,1)+substring(@first,1,1))
6 declare @FileNum int
7 select @FileNum=convert(int,substring(@first,6,1)+substring(@first,5,1))
8 select @FileNum,@PageNum
通过返回的@FileNum,@PageNum,查看表数据页结构
1 DBCC TRACEON (3604)
2 DBCC Page (7,1,227,1)
返回结果如下
View Code
二、查看索引的数据
1 --创建测试表,并添加索引
2 USE AdventureWorks
3 SELECT *
4 INTO dbo.Contacts_index
5 FROM Person.Contact
6 CREATE INDEX FullName ON Contacts_index(LastName,FirstName)
7 DBCC IND(AdventureWorks,Contacts_index,-1)
评论