更新时间:2023-02-07 10:41:44
有两个系统"您可以参考的目录视图:sys.indexes
和 sys.index_columns
.
There are two "sys" catalog views you can consult: sys.indexes
and sys.index_columns
.
那些将为您提供您可能想要的有关索引及其列的任何信息.
Those will give you just about any info you could possibly want about indices and their columns.
此查询与您要查找的内容非常接近:
This query's getting pretty close to what you're looking for:
SELECT
TableName = t.name,
IndexName = ind.name,
IndexId = ind.index_id,
ColumnId = ic.index_column_id,
ColumnName = col.name,
ind.*,
ic.*,
col.*
FROM
sys.indexes ind
INNER JOIN
sys.index_columns ic ON ind.object_id = ic.object_id and ind.index_id = ic.index_id
INNER JOIN
sys.columns col ON ic.object_id = col.object_id and ic.column_id = col.column_id
INNER JOIN
sys.tables t ON ind.object_id = t.object_id
WHERE
ind.is_primary_key = 0
AND ind.is_unique = 0
AND ind.is_unique_constraint = 0
AND t.is_ms_shipped = 0
ORDER BY
t.name, ind.name, ind.index_id, ic.is_included_column, ic.key_ordinal;