Skip to content

Instantly share code, notes, and snippets.

@terrancesnyder
Created October 17, 2011 14:01
Show Gist options
  • Save terrancesnyder/1292661 to your computer and use it in GitHub Desktop.
Save terrancesnyder/1292661 to your computer and use it in GitHub Desktop.
oracle get all FK and their tables
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