Created
October 17, 2011 14:01
-
-
Save terrancesnyder/1292661 to your computer and use it in GitHub Desktop.
oracle get all FK and their tables
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT uc.constraint_name||CHR(10) | |
|| '('||ucc1.TABLE_NAME||'.'||ucc1.column_name||')' constraint_source | |
, 'REFERENCES'||CHR(10) | |
|| '('||ucc2.TABLE_NAME||'.'||ucc2.column_name||')' references_column | |
FROM user_constraints uc | |
, user_cons_columns ucc1 | |
, user_cons_columns ucc2 | |
WHERE uc.constraint_name = ucc1.constraint_name | |
AND uc.r_constraint_name = ucc2.constraint_name | |
AND ucc1.POSITION = ucc2.POSITION -- Correction for multiple column primary keys. | |
AND uc.constraint_type = 'R' | |
ORDER BY ucc1.TABLE_NAME | |
, uc.constraint_name; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment