Created
March 30, 2015 02:38
-
-
Save rmsj/7d497efde1da7086518b to your computer and use it in GitHub Desktop.
Get all tables that reference a table.field on PostgreSQL
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 R.* | |
from INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE u | |
inner join INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS FK | |
on U.CONSTRAINT_CATALOG = FK.UNIQUE_CONSTRAINT_CATALOG | |
and U.CONSTRAINT_SCHEMA = FK.UNIQUE_CONSTRAINT_SCHEMA | |
and U.CONSTRAINT_NAME = FK.UNIQUE_CONSTRAINT_NAME | |
inner join INFORMATION_SCHEMA.KEY_COLUMN_USAGE R | |
ON R.CONSTRAINT_CATALOG = FK.CONSTRAINT_CATALOG | |
AND R.CONSTRAINT_SCHEMA = FK.CONSTRAINT_SCHEMA | |
AND R.CONSTRAINT_NAME = FK.CONSTRAINT_NAME | |
WHERE U.COLUMN_NAME = 'customer_contact_id' | |
AND U.TABLE_NAME = 'customer_contact' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment