Last active
July 13, 2016 08:29
-
-
Save ymauray/4e4ed07149f327ed4ddcc9cb9a8d24ba to your computer and use it in GitHub Desktop.
Find all tables referencing a given table's primary key
This file contains 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 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