List Foreign Keys, Parent and Referenced Columns

SELECT fk.name AS ForeignKey_Name, ob.name AS ParentTableName, col.name AS ParentColName, ob2.name AS ReferencedTableName, RCol.name AS ReferenceColName FROM sys.foreign_keys AS fk INNER JOIN sys.objects AS ob ON fk.parent_object_id = ob.object_id CROSS JOIN sys.objects AS ob2 INNER JOIN sys.foreign_key_columns AS fkc ON fk.object_id = fkc.constraint_object_id INNER JOIN sys.COLUMNS AS COL ON col.object_id Continue Reading