此查询不会找到未明确与约束结合使用的唯一索引:
select TC.Constraint_Name, CC.Column_Name
from information_schema.table_constraints TC
inner join information_schema.constraint_column_usage CC
on TC.Constraint_Name = CC.Constraint_Name
where TC.constraint_type = 'Unique'
order by TC.Constraint_Name
那么如何使用 INFORMATION_SCHEMA
create unique constraint PipelineSummary_CorrelationId on
bronze.AggregatedPipelineSummary (CorrelationId);
因此请使用 SQL Server 的本机目录视图,此处为 sys.indexes 查询sys.indexes,eg
select o.name table_name, i.name index_name, i.is_unique_constraint
from sys.objects o
join sys.indexes i
on o.object_id = i.object_id
where is_unique=1
and o.is_ms_shipped = 0