用于查找外键约束的SQL查询

时间:2016-07-22 08:14:21

标签: postgresql

我有一列,我想查找该列用作外语的多少个表以及使用该列的表的名称。我有PostgreSQL数据库。我正在使用PG管理工具

select R.TABLE_NAME 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.CONSTRAINT_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='M_InLine_ID'
AND U.TABLE_NAME = 'M_InLine'

我尝试了上面的查询,但它给出了任何输出 请帮帮我

0 个答案:

没有答案