查看表中某个列具有外键的所有表?

发布于 2024-11-09 22:51:13 字数 30 浏览 3 评论 0原文

这可能吗?如果是,涉及哪些表,可以在哪里查看。

Is this possible ? If yes, what are the tables involved, somewhere to look into .

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

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

发布评论

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

评论(3

清风挽心 2024-11-16 22:51:13

尝试这样的

select uc.table_name 
from sys.user_cons_columns ucc
join sys.user_constraints uc 
on uc.r_constraint_name = ucc.constraint_name
where constraint_type = 'R'
and ucc.table_name = :1
and ucc.column_name = :2

地方

:1 = referenced table
:2 = referenced column

Try something like this

select uc.table_name 
from sys.user_cons_columns ucc
join sys.user_constraints uc 
on uc.r_constraint_name = ucc.constraint_name
where constraint_type = 'R'
and ucc.table_name = :1
and ucc.column_name = :2

where

:1 = referenced table
:2 = referenced column
翻了热茶 2024-11-16 22:51:13
select * from user_constraints where r_constraint_name =<PK_NAME>

其中 是列的主键约束的名称

select * from user_constraints where r_constraint_name =<PK_NAME>

where <PK_NAME> is the name of the primary key constraint of the column

围归者 2024-11-16 22:51:13

有两个候选查询可能会有所帮助:

http://www.alberton.info/oracle_meta_info.html

SELECT alc.constraint_name,
          CASE alc.constraint_type
            WHEN 'P' THEN 'PRIMARY KEY'
            WHEN 'R' THEN 'FOREIGN KEY'
            WHEN 'U' THEN 'UNIQUE'
            WHEN 'C' THEN 'CHECK'
          END "constraint_type",
          alc.DELETE_RULE "on_delete",
          CASE alc.deferrable WHEN 'NOT DEFERRABLE' THEN 0 ELSE 1 END "deferrable",
          CASE alc.deferred WHEN 'IMMEDIATE' THEN 1 ELSE 0 END "initially_deferred",
          alc.search_condition,
          alc.table_name,
          cols.column_name,
          cols.position,
          r_alc.table_name "references_table",
          r_cols.column_name "references_field",
          r_cols.position "references_field_position"
     FROM all_cons_columns cols
LEFT JOIN all_constraints alc
       ON alc.constraint_name = cols.constraint_name
      AND alc.owner = cols.owner
LEFT JOIN all_constraints r_alc
       ON alc.r_constraint_name = r_alc.constraint_name
      AND alc.r_owner = r_alc.owner
LEFT JOIN all_cons_columns r_cols
       ON r_alc.constraint_name = r_cols.constraint_name
      AND r_alc.owner = r_cols.owner
      AND cols.position = r_cols.position
    WHERE alc.constraint_name = cols.constraint_name
      AND alc.constraint_name = 'TESTCONSTRAINTS_ID_FK'
      AND alc.table_name = 'TESTCONSTRAINTS2';

There are two candidate queries that might help here:

http://www.alberton.info/oracle_meta_info.html

SELECT alc.constraint_name,
          CASE alc.constraint_type
            WHEN 'P' THEN 'PRIMARY KEY'
            WHEN 'R' THEN 'FOREIGN KEY'
            WHEN 'U' THEN 'UNIQUE'
            WHEN 'C' THEN 'CHECK'
          END "constraint_type",
          alc.DELETE_RULE "on_delete",
          CASE alc.deferrable WHEN 'NOT DEFERRABLE' THEN 0 ELSE 1 END "deferrable",
          CASE alc.deferred WHEN 'IMMEDIATE' THEN 1 ELSE 0 END "initially_deferred",
          alc.search_condition,
          alc.table_name,
          cols.column_name,
          cols.position,
          r_alc.table_name "references_table",
          r_cols.column_name "references_field",
          r_cols.position "references_field_position"
     FROM all_cons_columns cols
LEFT JOIN all_constraints alc
       ON alc.constraint_name = cols.constraint_name
      AND alc.owner = cols.owner
LEFT JOIN all_constraints r_alc
       ON alc.r_constraint_name = r_alc.constraint_name
      AND alc.r_owner = r_alc.owner
LEFT JOIN all_cons_columns r_cols
       ON r_alc.constraint_name = r_cols.constraint_name
      AND r_alc.owner = r_cols.owner
      AND cols.position = r_cols.position
    WHERE alc.constraint_name = cols.constraint_name
      AND alc.constraint_name = 'TESTCONSTRAINTS_ID_FK'
      AND alc.table_name = 'TESTCONSTRAINTS2';
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文