简体   繁体   English

在SQL Developer中从外键中查找引用表

[英]Finding reference table from foreign key in SQL Developer

OK so I'm new to SQL and not very familiar with Oracle SQLDev, but the tool that I'm making requires that I access an Oracle database and gather some information. 好的,所以我是SQL的新手,并不熟悉Oracle SQLDev,但我正在制作的工具要求我访问Oracle数据库并收集一些信息。 I'm trying to figure what table a foreign key is pointing to. 我正在尝试计算外键指向的表。

This database has thousands of tables. 该数据库有数千个表。

Example: 例:

I got a table (TASKS) that contains the following columns [id, user, task_type, task_group]. 我有一个表(TASKS),其中包含以下列[id,user,task_type,task_group]。 The problem is that all of this values are ids which correspond to another table, and the table naming convention is not intuitive. 问题是所有这些值都是与另一个表对应的ID,并且表命名约定不直观。

So how can I find out what table task_type is a pointing to? 那么如何找出task_type指向哪个表?

select acc.table_name REFERENCING_TABLE_NAME, acc.column_name REFERENCING_COLUMN_NAME
from all_constraints ac1,
all_constraints ac2,
all_cons_columns acc
where ac1.constraint_type = 'P'
and ac1.table_name = :table_name
and ac2.r_constraint_name = ac1.constraint_name
and ac2.constraint_name = acc.constraint_name;

that should work 应该工作

see my post here (2nd answer) as to how you can add this as an extension in sqldeveloper: 请参阅我的帖子(第二个答案),了解如何将其添加为sqldeveloper中的扩展名:

How can I find which tables reference a given table in Oracle SQL Developer? 如何在Oracle SQL Developer中找到哪些表引用给定表?

select table_name, constraint_name, status, owner
from all_constraints
where r_owner = :r_owner
and constraint_type = 'R'
and r_constraint_name in
 (
   select constraint_name from all_constraints
   where constraint_type in ('P', 'U')
   and table_name = :r_table_name
   and owner = :r_owner
 )
order by table_name, constraint_name

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM