简体   繁体   English

SQL Server - 如何识别表是堆还是B树

[英]SQL Server - how to identify if table is heap or B-tree

SQL Server - 是否有一个系统表用于识别我的表是堆还是b-tree?

Yes, the catalog view sys.partitions holds this information. 是的,目录视图sys.partitions包含此信息。 The field index_id will tell you if a table is heap (index_id = 0) or b-tree (index_id > 0). 字段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'

From the documentation - Table and Index Organization : 从文档 - 表和索引组织

ID of the index within the object to which this partition belongs. 此分区所属的对象中的索引的ID。

 0 = heap 1 = clustered index 2 or greater = nonclustered 

Heaps are tables that have no clustered index. 堆是没有聚簇索引的表。 Nonclustered indexes have a B-tree index structure similar to the one in clustered indexes. 非聚簇索引具有类似于聚簇索引中的B树索引结构。

Each table that have't clustered index is a heap table. 每个没有聚簇索引的表都是一个堆表。 you can check clustered index on each table in order to determine that table is a heap table or no. 您可以检查每个表上的聚簇索引,以确定该表是堆表还是否。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在SQL Server中查找表的B树的高度 - Finding the height of the B-Tree of a table in SQL Server SQL Server 2012:性能列存储索引与B树 - SQL Server 2012: performance columnstore index vs B-tree 如何将wgs84坐标映射到sql server b树索引(不使用内置空间索引) - how to map wgs84 coordinates to sql server b-tree index (w/o using built in spatial indexes) SQL Server:写入t-log或更新b-tree后,SQL请求返回 - SQL Server: SQL request returns after writing to t-log or after b-tree is updated 数据库如何在B-Tree / B + Tree内部存储数据 - How Database stores data internally in B-Tree/B+Tree SQL Server 2012 如何确定表 A 中的所有值是否都在表 B 中 - SQL Server 2012 How to determine if all the values in table A are in table B SQL Server 2016 - 时态表 - 如何识别用户 - SQL Server 2016 - Temporal Table - how to identify the user 如何使用SQL Server时态表识别更改的值? - How to identify changed values using a SQL Server temporal table? 识别SQL Server表中的连续块 - Identify Consecutive Chunks in SQL Server Table SQL 服务器 - 映射表以识别要汇总的字段 - SQL Server - Mapping table to identify fields to sum
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM