ORACLE查詢表之間的主外來鍵關係

taogchan發表於2011-12-01
Select b.table_name 主鍵表名,
 
          b.column_name 主鍵列名,
           a.table_name 外來鍵表名,
           a.column_name 外來鍵列名
From (Select a.constraint_name,
                       b.table_name,
                       b.column_name,
                       a.r_constraint_name
          From user_constraints a, user_cons_columns b
         Where a.constraint_type = 'R'
           And a.constraint_name = b.constraint_name) a,
       (Select Distinct a.r_constraint_name, b.table_name, b.column_name
          From user_constraints a, user_cons_columns b
         Where a.constraint_type = 'R'
           And a.r_constraint_name = b.constraint_name) b
Where a.r_constraint_name = b.r_constraint_name

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/22392018/viewspace-712491/,如需轉載,請註明出處,否則將追究法律責任。

相關文章