Get the unique constraint columns list (in TSQL)?

前端 未结 6 1721
日久生厌
日久生厌 2021-02-01 01:56

I can get a list of unique constraints fairly easily with the following query:

select * from INFORMATION_SCHEMA.TABLE_CONSTRAINTS where CONSTRAINT_TYPE=\'UNIQUE\         


        
6条回答
  •  一整个雨季
    2021-02-01 02:35

    Ed is correct, the columns are exposed on the constraint column usage view, here is the SQL for it.

    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
    

提交回复
热议问题