答案 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