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.
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
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
oh..sorry...that was for MSSQL...I just noticed your question is in regards to Postgresql...my appologies
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?
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
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