SQL Server DB中所有索引和索引列的列表
如何获取SQL Server 2005+中所有索引和索引列的列表?我能得到的最接近的是:
select s.name, t.name, i.name, c.name from sys.tables t
inner join sys.schemas s on t.schema_id = s.schema_id
inner join sys.indexes i on i.object_id = t.object_id
inner join sys.index_columns ic on ic.object_id = t.object_id
inner join sys.columns c on c.object_id = t.object_id and
ic.column_id = c.column_id
where i.index_id > 0
and i.type in (1, 2) -- clustered & nonclustered only
and i.is_primary_key = 0 -- do not include PK indexes
and i.is_unique_constraint = 0 -- do not include UQ
and i.is_disabled = 0
and i.is_hypothetical = 0
and ic.key_ordinal > 0
order by ic.key_ordinal
这不是我想要的。
我想要的是,列出所有用户定义的索引(这意味着没有支持唯一约束和主键的索引)与所有列(按它们在索引定义中的显示方式排序)加上尽可能多的元数据。
呼如林
相关分类