如何在SQL Server中使用sysindexes表获取表索引和相关列?

时间:2011-07-26 09:49:47

标签: sql sql-server

1 个答案:

答案 0 :(得分:8)

sys.indexes视图有一列is_unique

select  i.name as IndexName
,       ic.key_ordinal as IndexColumnPosition
,       c.name as IndexColumnName
from    sys.indexes i
left join
        sys.index_columns ic
on      ic.object_id = i.object_id
        and ic.index_id = i.index_id
left join
        sys.columns c
on      c.object_id = ic.object_id
        and c.column_id = ic.column_id
where   i.object_id = object_id('YourTable')
        and i.is_unique = 1