2009-04-08 66 views

回答

12

這裏是a good article一個答案:

select owner,constraint_name,constraint_type,table_name,r_owner,r_constraint_name 
from all_constraints 
where constraint_type='R' 
and r_constraint_name in (select constraint_name from all_constraints 
where constraint_type in ('P','U') and table_name='TABLE_NAME'); 
+0

我將檢查該視圖 - 查詢返回具有FK的表,並且我需要指定一個表並獲取每個具有FK的其他表 – juan 2009-04-08 19:27:41

1

假設兩個父和子表都在同一個模式執行以下操作:

select t1.table_name child_table, t1.constraint_name, t2.table_name parent_table 

from user_constraints t1, user_constraints t2 

where t1.r_constraint_name = t2.constraint_name 

注意r_constraint_name中只填入FK (類型'R')的約束,所以自加入只返回感興趣的信息

0

如果我們知道父鍵,只是改變了juan與員工的答案tabl e

select * 
from user_constraints 
where R_CONSTRAINT_NAME='EMP_EMP_ID_PK' 
and constraint_type='R' 
相關問題