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


/ Published in: SQL
Save to your folder(s)



Copy this code and paste it in your HTML
  1. SELECT f.name 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

URL: http://blog.sqlauthority.com/2007/09/04/sql-server-2005-find-tables-with-foreign-key-constraint-in-database/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.