Posted By

ChrisCantley on 08/11/10


Tagged


Versions (?)

Find all Constraints on Object


 / Published in: SQL
 

  1. SELECT
  2. K_Table = FK.TABLE_NAME,
  3. FK_Column = CU.COLUMN_NAME,
  4. PK_Table = PK.TABLE_NAME,
  5. PK_Column = PT.COLUMN_NAME,
  6. Constraint_Name = C.CONSTRAINT_NAME
  7. FROM INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS C
  8. INNER JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS FK ON C.CONSTRAINT_NAME = FK.CONSTRAINT_NAME
  9. INNER JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS PK ON C.UNIQUE_CONSTRAINT_NAME = PK.CONSTRAINT_NAME
  10. INNER JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE CU ON C.CONSTRAINT_NAME = CU.CONSTRAINT_NAME
  11. INNER JOIN (
  12. SELECT i1.TABLE_NAME, i2.COLUMN_NAME
  13. FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS i1
  14. INNER JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE i2
  15. ON i1.CONSTRAINT_NAME = i2.CONSTRAINT_NAME
  16. WHERE i1.CONSTRAINT_TYPE = 'PRIMARY KEY'
  17. ) PT
  18. ON PT.TABLE_NAME = PK.TABLE_NAME
  19. WHERE PK.TABLE_NAME='tblImages'
  20. ORDER BY PK.TABLE_NAME, PT.COLUMN_NAME
  21.  

Report this snippet  

You need to login to post a comment.