Query Referential Integrity Constraints information from ORACLE db

this is how I queried Oracle DB to get information about Foreign keys.

SELECT A.CONSTRAINT_NAME,
C.TABLE_NAME PARENT_TABLE,C.COLUMN_NAME PARENT_COLUMN,
A.TABLE_NAME CHILD_TABLE,B.COLUMN_NAME CHILD_COLUMN

FROM USER_CONSTRAINTS A
INNER JOIN USER_CONS_COLUMNS  B
ON A.CONSTRAINT_NAME=B.CONSTRAINT_NAME

INNER JOIN USER_CONS_COLUMNS  C
ON A.R_CONSTRAINT_NAME=C.CONSTRAINT_NAME
WHERE A.CONSTRAINT_TYPE=’R’
ORDER BY C.TABLE_NAME

Tuesday, July 15th, 2008 Uncategorized

No comments yet.

Leave a comment

You must be logged in to post a comment.