欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

ORACLE查询外键关联表和列

程序员文章站 2022-04-21 10:12:53
...
select t1.table_name, 
       t2.table_name as "TABLE_NAME(R)", 
       t1.constraint_name, 
       t1.r_constraint_name as "CONSTRAINT_NAME(R)",
       a1.column_name, 
       a2.column_name as "COLUMN_NAME(R)"
from user_constraints t1, user_constraints t2, user_cons_columns a1, user_cons_columns a2 
where 
     t2.table_name = '表名称' and
      t1.r_constraint_name = t2.constraint_name and 
      t1.constraint_name = a1.constraint_name and 
      t1.r_constraint_name = a2.constraint_name