您好,我是小DAI,专注于数据库管理员相关的技术问答,请问有什么可以帮您?

sp_helpindex

语法


sp_helpindex <objname>,[<cmdname> | "terse"]

<h3>参数</h3>

<code><objname>
是当前数据库中表的名称。

<cmdname>
为显示索引信息而运行的命令。支持的命令有

  • help 显示 sp_helpindex 的使用信息。
  • showpartialindex 显示该数据库中所有部分索引
  • showlackindexpartition 显示表 <objname> 尚未构建部分索引分区的数据分区 "terse" sp_helpindex 显示降低的输出,并跳过分区相关的信息。terse 的输出包括:
  • 索引总数 -全局索引总数 -本地索引总数 -部分索引总数 sp_helpindex 显示输出中与 create index 语法保持一致的索引信息。

    示例

    示例 1

    显示 sysobjects 表上索引的类型:

sp_helpindex sysobjects



index_name index_keys index_description index_max_rows_per_page

index_fillfactor index_reservepagegap index_created

index_local

sysobjects id clustered, unique 0

0 0 Apr 12 2005 2:38PM

Global Index

ncsysobjects name, uid nonclustered, unique

0 0 Apr 12 2005 2:38PM

Global Index

(2 rows affected)

index_pt_name index_ptn_seg

---------------------- --------------

sysobjects_1 system

ncsysobjects_1 system



<h4>示例 2</h4>

显示有关 pubs2 数据库中 titles 表中的索引的信息。titles 表已分区,但 titleind 未分区。titleind 是一个非聚簇(单分区)全局索引:

sp_helpindex titles



index_name index_keys index_description index_max_rows_per_page

index_fillfactor index_reservepagegap index_created

index_local

titleind title nonclustered 0

Global Index

(1 row affected)

index_pt_name index_ptn_seg

---------------------- --------------

titleind_1232004389 default



<h4>示例 3</h4>

显示有关 mysalesdetail 表的索引信息。mysalesdetail 按 ord_num 列上的散列分区。已在 ord_num 中创建了具有三个分区的聚簇本地索引:

sp_helpindex mysalesdetail



index_name index_keys index_description index_max_rows_per_page

index_fillfactor index_reservepagegap index_created index_local

---------- ---------- ----------------- -----------------------

---------------- -------------------- ------------- -----------

clust_idx ord_num clustered 0

0 0 Apr 12 2005 2:38PM Local Index

(1 row affected)

index_pt_name index_ptn_seg

---------------------- --------------

clust_idx_1344004788 default

clust_idx_1360004845 default

clust_idx_1376004902 default



<h4>示例 4</h4>

显示有关表 big_table 中创建的索引的信息:

sp_helpindex big_table



<h4>示例 5</h4>

显示 sp_helpindex 的使用信息:

sp_helpindex null, help



<h4>示例 6</h4>

显示当前数据库中的所有部分索引:

sp_helpindex null, showpartialindex



<h4>示例 7</h4>

显示表 big_table 上的所有部分索引:

sp_helpindex big_table, showpartialindex



<h4>示例 8</h4>

显示不包括表 big_table 上部分索引分区的所有数据分区:

sp_helpindex big_table, showlackindexpartition



<h4>示例 9</h4>

显示基于函数的索引:

create index sum_sales on mytitles (price * total_sales)

sp_helpindex mytitles



Object has the following indexes

index_name index_keys index_description index_max_rows_per_page

index_fillfactor index_reservepagegap index_created index_local

---------- ---------- ----------------- -----------------------

---------------- -------------------- ------------- -----------

sum_sales sybfi2_1 nonclustered 0

0 0 Oct 12 2005 3:34PM Global Index

(1 row affected)

index_ptn_name index_ptn_seg

-------------------- -------------

sum_sales_1724867646 default

(1 row affected)

Object has the following functional index keys

Internal_Index_Key_Name

sybfi2_1

(1 row affected)

Expression

price * total_sales

(return status = 0)



<h4>示例 10</h4>

显示 syspartitions 索引的缩写信息集:

sp_helpindex syspartitions, "terse"



Object has the following indexes

index description

unique clustered index csyspartitions on syspartitions ( id, indid, partitionid ) -- global index

unique nonclustered index ncsyspartitions on syspartitions ( partitionid, indid ) -- global index

unique nonclustered index nc2syspartitions on syspartitions ( id, indid, name ) -- global index

(3 rows affected)

total_indexes global_indexes local_indexes partial_indexes

------------- -------------- ------------- ---------------

3 3 0 0

(1 row affected)

(return status = 0)

```

用法

使用 sp_helpindex 时,还存在一些其它注意事项:

  • sp_helpindex 列出表上的所有索引,包括通过定义由 create table 或 alter table 语句定义的唯一键或主键约束创建的索引。

  • sp_helpindex 显示指派给表上索引的任何属性(例如,高速缓存绑定)。

  • sp_helpindex 将显示:

    a) 每个索引的分区信息。

    b) 索引是本地索引还是全局索引,聚簇索引还是非聚簇索引。

    c) 索引的 max_rows_per_page 设置。

    d) 有关仅数据锁定表上的聚簇索引的信息。

    e) 仅数据锁定表中聚簇索引的索引 ID (indid) 不等于 1。

    f) 键的列顺序,指示键是按升序还是降序排列。

    g) 空间管理属性值。

    h) 按照该顺序的键列的名称。只显示降序顺序。例如,如果在列 a ASC、b DESC、c ASC 上有一个索引,则“index_keys”显示“a, b DESC, c”。