1.根据数据记录查看当前记录所在的文件编号、page页、以及在页中的插槽。
示例如下:
SELECT top 10 %%physloc%%, sys.fn_physlocFormatter (%%physloc%%) AS RID FROM tableName
--注意;在64位系统中sys.fn_physlocFormatter 整理出来的格式有时候不对,需要手工根据physloc来计算,计算的方法是:
以字节为单位倒叙,如
0x0702000001002200倒叙后是
0x0022000100000207
前四位0022表示插槽号2*16+2 = 34,接下来的四位0001表示文件号,余下的00000207表示文件号2*16*16+7 = 519
DBCC TraceOn(3604) DBCC page(数据库名,1,40995,0) DBCC TraceOff(3604)
2.根据sys.system_internals_allocation_units(该视图同sys.allocation_units)获得首页
select OBJECT_NAME(object_id) as Name,p.rows,a.type_desc ,a.total_pages,a.first_page ,a.first_iam_page,a.root_page from sys.partitions P join sys.system_internals_allocation_units a on p.partition_id = a.container_id where object_id = object_id(‘dbo.Dumplpt‘)
首页页码按照16进制形式保存,同上按字节反序后,前两组表示2字节文件编号,后4组表示页编号。可用如下函数来返回文件号和页码:
CREATE FUNCTION convert_page_nums (@page_num binary(6)) RETURNS varchar(11) AS BEGIN RETURN(convert(varchar(2), (convert(int, substring(@page_num, 6, 1)) * power(2, 8)) + (convert(int, substring(@page_num, 5, 1)))) + ‘:‘ + convert(varchar(11), (convert(int, substring(@page_num, 4, 1)) * power(2, 24)) + (convert(int, substring(@page_num, 3, 1)) * power(2, 16)) + (convert(int, substring(@page_num, 2, 1)) * power(2, 8)) + (convert(int, substring(@page_num, 1, 1)))) ) END;
3.使用DBCC IND命令,示例如下:
DBCC IND(testLogDB,‘dbo.Dumplpt‘,-1)
将返回形如下结果:
PageFID PagePID IAMFID IAMPID ObjectID IndexID PartitionNumber PartitionID iam_chain_type PageType IndexLevel NextPageFID NextPagePID PrevPageFID PrevPagePID 1 197 NULL NULL 69575286 0 1 72057594038976512 In-row data 10 NULL 0 0 0 0 1 196 1 197 69575286 0 1 72057594038976512 In-row data 1 0 0 0 0 0 1 198 1 197 69575286 0 1 72057594038976512 In-row data 1 0 0 0 0 0 1 199 1 197 69575286 0 1 72057594038976512 In-row data 1 0 0 0 0 0 1 200 1 197 69575286 0 1 72057594038976512 In-row data 1 0 0 0 0 0 1 201 1 197 69575286 0 1 72057594038976512 In-row data 1 0 0 0 0 0 1 202 1 197 69575286 0 1 72057594038976512 In-row data 1 0 0 0 0 0 1 203 1 197 69575286 0 1 72057594038976512 In-row data 1 0 0 0 0 0 1 204 1 197 69575286 0 1 72057594038976512 In-row data 1 0 0 0 0 0 1 208 1 197 69575286 0 1 72057594038976512 In-row data 1 0 0 0 0 0 1 209 1 197 69575286 0 1 72057594038976512 In-row data 1 0 0 0 0 0 1 210 1 197 69575286 0 1 72057594038976512 In-row data 1 0 0 0 0 0 1 211 1 197 69575286 0 1 72057594038976512 In-row data 1 0 0 0 0 0 1 212 1 197 69575286 0 1 72057594038976512 In-row data 1 0 0 0 0 0 1 213 1 197 69575286 0 1 72057594038976512 In-row data 1 0 0 0 0 0
时间: 2024-10-11 18:11:29