SqlServer找頁鏈

來源:互聯網
上載者:User

標籤:

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_pagefrom sys.partitions P join sys.system_internals_allocation_units a on p.partition_id = a.container_idwhere 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)

將返回形如下結果:

PageFIDPagePIDIAMFIDIAMPIDObjectIDIndexIDPartitionNumberPartitionIDiam_chain_typePageTypeIndexLevelNextPageFIDNextPagePIDPrevPageFIDPrevPagePID1197NULLNULL695752860172057594038976512In-row data10NULL000011961197695752860172057594038976512In-row data10000011981197695752860172057594038976512In-row data10000011991197695752860172057594038976512In-row data10000012001197695752860172057594038976512In-row data10000012011197695752860172057594038976512In-row data10000012021197695752860172057594038976512In-row data10000012031197695752860172057594038976512In-row data10000012041197695752860172057594038976512In-row data10000012081197695752860172057594038976512In-row data10000012091197695752860172057594038976512In-row data10000012101197695752860172057594038976512In-row data10000012111197695752860172057594038976512In-row data10000012121197695752860172057594038976512In-row data10000012131197695752860172057594038976512In-row data100000

  

SqlServer找頁鏈

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.