如何在oracle中找到外约束键的父表?

时间:2022-07-09 04:37:14

How can I find the parent table(s) of foreign constraint(s) on a table key in oracle? I'm needing to create a dropdown of all of the values that can be selected for this column I'm looking at and need to know the parent so I can look up its sibling values.

如何在oracle中找到表键上的外约束的父表?我需要为我正在查看的这一列创建所有可选择的值的下拉列表,并需要知道父值,以便查找它的兄弟值。

1 个解决方案

#1


2  

You can query this information from all_constraints (or user_constraints or dba_constraints, of course). Unfortunately, you can only retrieve the name of the constraint a foreign key refers to, so you'll have to use a sub query or a self join to retrieve the referring table:

您可以从all_constraints(当然可以从user_constraints或dba_constraints)查询这些信息。不幸的是,您只能检索外键引用的约束的名称,因此必须使用子查询或自连接来检索引用表:

SELECT r.table_name
FROM   user_constraints t
JOIN   user_constraints r ON t.r_constraint_name = r.constraint_name
WHERE  t.constraint_type = 'R' AND t.table_name = 'SOME_TABLE'

#1


2  

You can query this information from all_constraints (or user_constraints or dba_constraints, of course). Unfortunately, you can only retrieve the name of the constraint a foreign key refers to, so you'll have to use a sub query or a self join to retrieve the referring table:

您可以从all_constraints(当然可以从user_constraints或dba_constraints)查询这些信息。不幸的是,您只能检索外键引用的约束的名称,因此必须使用子查询或自连接来检索引用表:

SELECT r.table_name
FROM   user_constraints t
JOIN   user_constraints r ON t.r_constraint_name = r.constraint_name
WHERE  t.constraint_type = 'R' AND t.table_name = 'SOME_TABLE'