簡單的資料表統計
USER_CONS_OBJ_COLUMNS
USER_CONS_OBJ_COLUMNS displays information about the types that object columns (or attributes) or collection elements have been constrained to,
in the tables owned by the current user. Its columns (except for OWNER) are the same as those in ALL_CONS_OBJ_COLUMNS.
USER_CONS_OBJ_COLUMNS displays information about the types that object columns (or attributes) or collection elements have been constrained to,
in the tables owned by the current user. Its columns (except for OWNER) are the same as those in ALL_CONS_OBJ_COLUMNS.
USER_CONS_COLUMNS
USER_CONS_COLUMNS describes columns that are owned by the current user and that are specified in constraint definitions.
Its columns are the same as those in "ALL_CONS_COLUMNS".
在當前使用者的約束中用到的列都會在檢視user_cons_columns中記錄。
也就是說,如果我要顯示哪些列是主鍵、外來鍵,可以通過此檢視來獲取。
也就是說,如果我要顯示哪些列是主鍵、外來鍵,可以通過此檢視來獲取。
檢視
select ucc.table_name,ucc.column_name,ucc.constraint_name,
decode(uc.constraint_type,'P','主鍵','F','外來鍵')
from user_cons_columns ucc
inner join user_constraints uc
on ucc.constraint_name=uc.constraint_name
where ucc.constraint_name not like '%$%'
and uc.constraint_type in ('P','F');
select ucc.table_name,ucc.column_name,ucc.constraint_name,
decode(uc.constraint_type,'P','主鍵','F','外來鍵')
from user_cons_columns ucc
inner join user_constraints uc
on ucc.constraint_name=uc.constraint_name
where ucc.constraint_name not like '%$%'
and uc.constraint_type in ('P','F');
現在要得到一個表格,需要的列為:
表名稱 欄位名稱 中文解釋 型別 備註
表名稱 欄位名稱 中文解釋 型別 備註
備註中顯示該列是否為主鍵、外來鍵
我的想法是:
select a.table_name,a.column_name,b.comments ,a.data_type,
/*ucc.constraint_name,*/decode(uc.constraint_type,'P','主鍵','R','外來鍵')
from dba_tab_cols a
left join dba_col_comments b
on a.table_name=b.TABLE_NAME
and a.column_name=b.column_name
left join user_cons_columns ucc
on ucc.table_name=a.table_name
and ucc.column_name=a.column_name
and ucc.constraint_name not like '%$%'
left join user_constraints uc
on ucc.constraint_name=uc.constraint_name
and uc.constraint_type in ('P','R')
where a.owner = 'ATT'
and a.table_name not like '%$%'
and a.table_name not in ('TEST','T')
order by a.table_name,a.column_id;
select a.table_name,a.column_name,b.comments ,a.data_type,
/*ucc.constraint_name,*/decode(uc.constraint_type,'P','主鍵','R','外來鍵')
from dba_tab_cols a
left join dba_col_comments b
on a.table_name=b.TABLE_NAME
and a.column_name=b.column_name
left join user_cons_columns ucc
on ucc.table_name=a.table_name
and ucc.column_name=a.column_name
and ucc.constraint_name not like '%$%'
left join user_constraints uc
on ucc.constraint_name=uc.constraint_name
and uc.constraint_type in ('P','R')
where a.owner = 'ATT'
and a.table_name not like '%$%'
and a.table_name not in ('TEST','T')
order by a.table_name,a.column_id;
但對於既是主鍵、也是外來鍵的列,不能用此方法,因為其會產生兩條記錄。
根源在user_cons_columns,該表中既是主鍵,也是外來鍵的列,對應兩條記錄。
最後我們將結果改成了以下形式
TABLE_NAME COLUMN_NAME COMMENTS DATA_TYPE PK_YN FK_YN
TABLE_NAME COLUMN_NAME COMMENTS DATA_TYPE PK_YN FK_YN
pk_yn、fk_yn分別表示是否為主、外來鍵。
若生成html格式的結果,步驟為:
column table_name format a30
column column_name format a30
column comments format a50
column data_type format a20
column pk_yn format a5
column fk_yn format a5
set linesize 3000
set pagesize 10000
set trimspool on
set mark html on entmap off
spool a.html
spool off
column column_name format a30
column comments format a50
column data_type format a20
column pk_yn format a5
column fk_yn format a5
set linesize 3000
set pagesize 10000
set trimspool on
set mark html on entmap off
spool a.html
spool off
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/26451536/viewspace-767212/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 資料統計表外掛,highcharts外掛的簡單應用
- 關鍵字: 讀取表單中最簡單的資料
- 資料庫表連線的簡單解釋資料庫
- 簡單Sql語句統計每年每個月的資料,每個月為資料的每列,簡單SQL練習SQL
- sql統計各種奇葩的資料庫表資料SQL資料庫
- 修復DBF資料表檔案的簡單方法 (轉)
- 實時計算,流資料處理系統簡介與簡單分析
- 簡單的BBS論壇 資料庫設計資料庫
- 微信如何在群裡進行資料統計,教你傳送表單網頁輕鬆統計資料網頁
- 簡單資料庫及表建立shell指令碼資料庫指令碼
- 資料庫設計簡單入門資料庫
- 如何建立最簡單的 ABAP 資料庫表,以及編碼從資料庫表中讀取資料 (上)資料庫
- SSIS 開發篇-做一個簡單的SqlServer資料表資料遷移SQLServer
- Oracle 資料倉儲簡單時間維度表的建立Oracle
- 簡單介紹mysql如何刪除資料表和關聯的資料表刪除詳情MySql
- 收集統計資訊的簡單操作
- 簡單的資料輸入
- [實踐] 為原型系統設計簡單的純文字資料交換協議原型協議
- DB2_收集表統計資料DB2
- 兩種簡單分析和優化MySQL資料庫表的方法優化MySql資料庫
- 簡單的選課系統(2)——資料庫的連線資料庫
- 一個表單中的資料新增到不同的資料表中
- POST表單資料大小的限制
- JAVA簡單的複習資料Java
- iOS 簡單資料的讀寫iOS
- [轉帖]達夢資料庫-統計資料表資料量及空間表大小資料庫
- 資料字典和固定表統計資訊更新
- Ajax 提交表單資料
- 表單資料驗證
- 表單資料相關
- Oracle GoldenGate系統之----單向同步資料表OracleGo
- [實踐] 為原型系統設計簡單的純文字資料交換協議 之二原型協議
- 內外網資料的簡單單向同步
- 計算機更喜歡清單型資料表!!!計算機
- SQL Server一個表新增資料,引發另一個表更新資料 的一個簡單觸發器例子SQLServer觸發器
- 資料分析 | 用 SeaTable 表格快速統計分析訂單資料
- 表單Form簡介——表單按鈕ORM
- 利用js解析php的表單資料JSPHP