SELECT OBJECT_NAME(fc.parent_object_id) AS FROM_TABLE
, OBJECT_NAME(fc.referenced_object_id) AS TO_TABLE
, from_c.name AS FROM_COLUMN_NAME
, to_c.name AS TO_COLUMN_NAME
, fk_obj.name AS FK_NAME
, fk_obj.create_date AS FK_CREATE_DATE
  FROM sys.foreign_key_columns fc
  JOIN sys.columns to_c
    ON to_c.object_id = fc.referenced_object_id
   AND to_c.column_id = fc.referenced_column_id
  JOIN sys.columns from_c
    ON from_c.object_id = fc.parent_object_id
   AND from_c.column_id = fc.parent_column_id
  JOIN sys.objects fk_obj
    ON fk_obj.object_id = fc.constraint_object_id
 ORDER BY OBJECT_NAME(from_c.object_id);

+ Recent posts