sys.index_columns (Transact-SQL)

属于 sys.indexes 索引或未排序的表(堆)的每个列都对应一行。

适用范围:SQL Server(SQL Server 2008 至当前版本),Windows Azure SQL Database(初始版本至当前版本)。

列名

数据类型

说明

object_id

int

定义了索引的对象的 ID。

index_id

int

定义了列的索引的 ID。

index_column_id

int

索引列的 ID。 index_column_id 仅在 index_id 内是唯一的。

column_id

int

object_id 中的列的 ID。

0 = 非聚集索引中的行标识符 (RID)。

column_id 仅在 object_id 中是唯一的。

key_ordinal

tinyint

键列集内的序数(从 1 开始)。

0 = 不是键列,或者是 XML 索引、列存储索引或空间索引。

备注

XML 索引或空间索引不能是键,原因是它们的基础列不是可比的,也就是说,无法对其值进行排序。

partition_ordinal

tinyint

分区列集内的序数(从 1 开始)。 聚集列存储索引可以具有最多 1 个分区列。

0 = 非分区列。

is_descending_key

bit

1 = 索引键列采用降序排序。

0 = 索引键列的排序方向为升序,或者列是列存储或哈希索引的一部分。

is_included_column

bit

1 = 列是使用 CREATE INDEX INCLUDE 子句添加到索引的非键列,或者列是列存储索引的一部分。

0 = 列不是包含列。

由于不是聚集键的一部分而隐式添加的列不列在 sys.index_columns 中。

由于是分区列而隐式添加的列作为 0 返回。

权限

目录视图中仅显示用户拥有的安全对象的元数据,或用户对其拥有某些权限的安全对象的元数据。 有关详细信息,请参阅元数据可见性配置

示例

下例返回表 Production.BillOfMaterials 的所有索引和索引列。

USE AdventureWorks2012;
GO
SELECT i.name AS index_name
    ,COL_NAME(ic.object_id,ic.column_id) AS column_name
    ,ic.index_column_id
    ,ic.key_ordinal
,ic.is_included_column
FROM sys.indexes AS i
INNER JOIN sys.index_columns AS ic 
    ON i.object_id = ic.object_id AND i.index_id = ic.index_id
WHERE i.object_id = OBJECT_ID('Production.BillOfMaterials');

下面是结果集:

index_name                                                 column_name        index_column_id key_ordinal is_included_column
---------------------------------------------------------- -----------------  --------------- ----------- -------------
AK_BillOfMaterials_ProductAssemblyID_ComponentID_StartDate ProductAssemblyID  1               1           0
AK_BillOfMaterials_ProductAssemblyID_ComponentID_StartDate ComponentID        2               2           0
AK_BillOfMaterials_ProductAssemblyID_ComponentID_StartDate StartDate          3               3           0
PK_BillOfMaterials_BillOfMaterialsID                       BillOfMaterialsID  1               1           0
IX_BillOfMaterials_UnitMeasureCode                         UnitMeasureCode    1               1           0

(5 row(s) affected)

请参阅

参考

对象目录视图 (Transact-SQL)

目录视图 (Transact-SQL)

sys.indexes (Transact-SQL)

sys.objects (Transact-SQL)

CREATE INDEX (Transact-SQL)

sys.columns (Transact-SQL)

概念

查询 SQL Server 系统目录常见问题