Posted By

g8rpal on 09/03/10


sql key 2005 MS constraints Foreign

Versions (?)

Who likes this?

1 person have marked this snippet as a favorite


SQL SERVER – 2005 – Find Tables With Foreign Key Constraint in Database

 / Published in: SQL


  1. SELECT AS ForeignKey,
  2. OBJECT_NAME(f.parent_object_id) AS TableName,
  3. COL_NAME(fc.parent_object_id,
  4. fc.parent_column_id) AS ColumnName,
  5. OBJECT_NAME (f.referenced_object_id) AS ReferenceTableName,
  6. COL_NAME(fc.referenced_object_id,
  7. fc.referenced_column_id) AS ReferenceColumnName,
  8. f.update_referential_action_desc AS UpdateAction,
  9. f.delete_referential_action_desc AS DeleteAction
  10. FROM sys.foreign_keys AS f
  11. INNER JOIN sys.foreign_key_columns AS fc
  12. ON f.OBJECT_ID = fc.constraint_object_id
  13. ORDER BY TableName ASC, ColumnName ASC

Report this snippet  

You need to login to post a comment.