I have created a unique constraint in an SQL Server Database using the following statement:
ALTER TABLE mytable ADD CONSTRAINT mytable_unique UNIQUE (uid)
How can I get all unique constraint names programmatically with C# SQLConnection object?
I have created a unique constraint in an SQL Server Database using the following statement:
ALTER TABLE mytable ADD CONSTRAINT mytable_unique UNIQUE (uid)
How can I get all unique constraint names programmatically with C# SQLConnection object?
query on information_schema.constraint_column_usage
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
You can also get these from sys.key_constraints:
select name from sys.key_constraints where type = 'UQ'