[英]SQL Server - how to identify if table is heap or B-tree
SQL Server - 是否有一個系統表用於識別我的表是堆還是b-tree?
是的,目錄視圖sys.partitions包含此信息。 字段index_id
將告訴您表是堆(index_id = 0)還是b-tree(index_id> 0)。
select
o.name,
o.object_id,
case
when p.index_id = 0 then 'Heap'
when p.index_id = 1 then 'Clustered Index/b-tree'
when p.index_id > 1 then 'Non-clustered Index/b-tree'
end as 'Type'
from sys.objects o
inner join sys.partitions p on p.object_id = o.object_id
where name = 'YourTableName'
從文檔 - 表和索引組織 :
此分區所屬的對象中的索引的ID。
0 = heap 1 = clustered index 2 or greater = nonclustered
堆是沒有聚簇索引的表。 非聚簇索引具有類似於聚簇索引中的B樹索引結構。
每個沒有聚簇索引的表都是一個堆表。 您可以檢查每個表上的聚簇索引,以確定該表是堆表還是否。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.