Skip to content

Instantly share code, notes, and snippets.

@ymauray
Last active July 13, 2016 08:29
Show Gist options
  • Save ymauray/4e4ed07149f327ed4ddcc9cb9a8d24ba to your computer and use it in GitHub Desktop.
Save ymauray/4e4ed07149f327ed4ddcc9cb9a8d24ba to your computer and use it in GitHub Desktop.
Find all tables referencing a given table's primary key
SELECT S.TABLE_NAME SOURCE,
S.CONSTRAINT_NAME CONTRAINTE,
T.TABLE_NAME CIBLE,
T.CONSTRAINT_NAME PK
FROM USER_CONSTRAINTS S,
USER_CONSTRAINTS T
WHERE T.TABLE_NAME = '<target_table>'
AND T.CONSTRAINT_TYPE = 'P'
AND S.R_CONSTRAINT_NAME = T.CONSTRAINT_NAME;
---
SELECT DISTINCT(S.TABLE_NAME) SOURCE,
T.TABLE_NAME CIBLE,
T.CONSTRAINT_NAME PK
FROM USER_CONSTRAINTS S,
USER_CONSTRAINTS T
WHERE T.TABLE_NAME = '<target_table>'
AND T.CONSTRAINT_TYPE = 'P'
AND S.R_CONSTRAINT_NAME = T.CONSTRAINT_NAME
ORDER BY S.TABLE_NAME ASC;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment