Use below query to get a List of Database Dependencies Object:
SELECT OBJECT_NAME(FKC.PARENT_OBJECT_ID) Foreign_Key_Table,
C2.NAME Foreign_Key_Field,
OBJECT_NAME(FKC.REFERENCED_OBJECT_ID) Primary_Key_Table,
C3.NAME Primary_Key_Field,
OBJECT_NAME(FKC.CONSTRAINT_OBJECT_ID) Relation_Name
FROM SYS.FOREIGN_KEY_COLUMNS FKC
JOIN SYS.COLUMNS C2 ON FKC.PARENT_OBJECT_ID = C2.OBJECT_ID
AND FKC.PARENT_COLUMN_ID = C2.COLUMN_ID
JOIN SYS.COLUMNS C3 ON FKC.REFERENCED_OBJECT_ID = C3.OBJECT_ID
AND FKC.REFERENCED_COLUMN_ID = C3.COLUMN_ID
ORDER BY Foreign_Key_Table
GO
SELECT OBJECT_NAME(FKC.PARENT_OBJECT_ID) Foreign_Key_Table,
C2.NAME Foreign_Key_Field,
OBJECT_NAME(FKC.REFERENCED_OBJECT_ID) Primary_Key_Table,
C3.NAME Primary_Key_Field,
OBJECT_NAME(FKC.CONSTRAINT_OBJECT_ID) Relation_Name
FROM SYS.FOREIGN_KEY_COLUMNS FKC
JOIN SYS.COLUMNS C2 ON FKC.PARENT_OBJECT_ID = C2.OBJECT_ID
AND FKC.PARENT_COLUMN_ID = C2.COLUMN_ID
JOIN SYS.COLUMNS C3 ON FKC.REFERENCED_OBJECT_ID = C3.OBJECT_ID
AND FKC.REFERENCED_COLUMN_ID = C3.COLUMN_ID
ORDER BY Foreign_Key_Table
GO
No comments:
Post a Comment