Last active
November 3, 2015 14:14
-
-
Save kdarty/659b8e02e353e8da04db to your computer and use it in GitHub Desktop.
The following SQL Script will retrieve a list of all "Unique" Constraints for a given Database. This is intended for use within SQL Server. Other Constraint Types that can be queried: Foreign Key and Primary Key
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- StackOverflow Discussion: | |
-- http://stackoverflow.com/questions/2675168/get-the-unique-constraint-columns-list-in-tsql | |
SELECT TC.CONSTRAINT_NAME, | |
CC.COLUMN_NAME, | |
TC.TABLE_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; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment