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

发布于 2024-12-21 19:06:46 字数 262 浏览 2 评论 0原文

好的,我是 SQL 新手,对 Oracle SQLDev 不太熟悉,但我正在制作的工具要求我访问 Oracle 数据库并收集一些信息。我试图弄清楚外键指向哪个表。

该数据库有数千张表。

示例:

我有一个表 (TASKS),其中包含以下列 [id、user、task_type、task_group]。问题是所有这些值都是对应于另一个表的 id,并且表命名约定并不直观。

那么我怎样才能找到task_type指向哪个表呢?

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. 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]. The problem is that all of this values are ids which correspond to another table, and the table naming convention is not intuitive.

So how can I find out what table task_type is a pointing to?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

薄凉少年不暖心 2024-12-28 19:06:46
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;

那应该有效

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

白芷 2024-12-28 19:06:46

请参阅我的帖子(第二个答案),了解如何将其添加为 sqldeveloper 中的扩展:

如何查找哪些表引用了 Oracle SQL Developer 中的给定表?

see my post here (2nd answer) as to how you can add this as an extension in sqldeveloper:

How can I find which tables reference a given table in Oracle SQL Developer?

护你周全 2024-12-28 19:06:46
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
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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文