Link to home
Create AccountLog in
Avatar of mock5c
mock5c

asked on

Query to list table's foreign key constraints

Is there a query that I can run to list all tables that depend on a certain table

e.g.  all tables that depend on tblData

They currently have a foreign key defined and I would like a way to quickly list these tables.
ASKER CERTIFIED SOLUTION
Avatar of Zippit
Zippit

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of Zippit
Zippit

oh..sorry...that was for MSSQL...I just noticed your question is in regards to Postgresql...my appologies
Avatar of mock5c

ASKER

They query can be run under postgres.  However, many of my constraint names are simply $1, $2, etc.  I take it that it would be impossible to figure out using that query?
Avatar of mock5c

ASKER

The query only required a minor modification to work with Postgres.  The beginning section

K_Table  = FK.TABLE_NAME,
FK_Column = CU.COLUMN_NAME,
PK_Table  = PK.TABLE_NAME,
PK_Column = PT.COLUMN_NAME,
Constraint_Name = C.CONSTRAINT_NAME

had to be changed to:

FK.TABLE_NAME as K_Table,
CU.COLUMN_NAME as FK_Column,
PK.TABLE_NAME as PK_Table,
PT.COLUMN_NAME as PK_Column,
C.CONSTRAINT_NAME as Constraint_Name