您好,我想要加入這兩個查詢,最終得到一個具有表名稱,表中的列數和具有外鍵的列數。SQL將兩個查詢合併爲一個
,該查詢產生的表名和列數
select t.table_name, count(t.table_name)
from all_constraints t
where owner = 'PARRANDEROS' group by t.table_name;
其他查詢外鍵計數。
select table_name, count(constraint_type)
from all_constraints
where owner = 'PARRANDEROS' and constraint_type ='R'group by table_name;
如何加入這兩個查詢?我使用Oracle數據庫。
編輯:有人告訴我,我沒有選擇每個表中的列數。那麼如何計算數據庫中每個表的數量?
我不確定我關注。這兩個查詢都不會返回您所說的結果。這兩個查詢都會返回表上的約束條數。它們都不是特定於外鍵的,它們也不與表中的列數或具有外鍵約束的列數有關。你是否假設所有的外鍵約束都在單列而不是複合鍵? – 2012-03-01 22:38:54
對不起,我只是更新第二個查詢,現在它選擇所有與外鍵約束的列。 – serpiente 2012-03-01 22:46:16
您是不是想要從all_tab_columns獲取列計數? – Joey 2012-03-01 22:47:15