I need a query that shows the Parent Table, Child Table, Relationships Name along with Primary Key (PK) and Foreign Key (FK) in my physical model. Will also be nice to have Datatypes for both PK and FK Columns along with Null Option.
Solution:
Here is a query that will show the parent table name, its PK name, its datatype, relationship name, the child table name, its FK name, its datatype and Null option.
SELECT
Rel.Name 'Relationship Name' ,
Tran(PEn.Physical_Name) 'Parent Entity Name' ,
Tran(CEn.Physical_Name) 'Child Entity Name' ,
Tran(Pat.Physical_Name) 'Parent Attribute Name' ,
PAt.Physical_Data_Type 'PK Datatype' ,
Tran(CAt.Physical_Name) 'Child Attribute Name',
CAt.Physical_Data_Type 'FK Datatype'
FROM
Relationship Rel
LEFT OUTER JOIN Entity PEn
ON Rel.Parent_Entity_Ref = PEn.Id@
LEFT OUTER JOIN Entity CEn
ON Rel.Child_Entity_Ref = CEn.Id@
LEFT OUTER JOIN Attribute CAt
ON CAt.Parent_Relationship_Ref = Rel.id@
LEFT OUTER JOIN Attribute PAt
ON CAt.Parent_Attribute_Ref = PAt.Id@