Oracle資料庫中,知道一張表,查詢與其有主外鍵關係的表,oracle資料庫

來源:互聯網
上載者:User

Oracle資料庫中,知道一張表,查詢與其有主外鍵關係的表,oracle資料庫

          --查外鍵表NC56.CSCI有無對應的主鍵表           SELECT a.owner,                  A.TABLE_NAME      primary_table_name,                  A.CONSTRAINT_NAME primary_table_key_name,                  b.owner,                  B.TABLE_NAME      foreign_table_name,                  B.CONSTRAINT_NAME foreign_table_foreign_key_name,                  B.STATUS          foreign_table_foreign_key_stat             FROM DBA_CONSTRAINTS A, DBA_CONSTRAINTS B            WHERE A.CONSTRAINT_NAME = B.R_CONSTRAINT_NAME              and B.CONSTRAINT_TYPE = 'R'              AND b.TABLE_NAME = 'CSCI' and a.owner='NC56' and b.owner='NC56'            ORDER BY 1, 2, 3, 4;            
           --查主鍵表NC56.CBH有無對應的外鍵表           SELECT a.owner,                 A.TABLE_NAME      primary_table_name,                  A.CONSTRAINT_NAME primary_table_key_name,                  b.owner,                  B.TABLE_NAME      foreign_table,                  B.CONSTRAINT_NAME foreign_table_foreign_key_name,                  B.STATUS          foreign_table_foreign_key_stat             FROM DBA_CONSTRAINTS A, DBA_CONSTRAINTS B            WHERE A.CONSTRAINT_NAME = B.R_CONSTRAINT_NAME              and B.CONSTRAINT_TYPE = 'R'              AND a.TABLE_NAME = 'CBH' and a.owner='NC56' and  b.owner='NC56'            ORDER BY 1, 2, 3, 4;


 

著作權聲明:本文為博主原創文章,未經博主允許不得轉載。

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.