Oracle查詢表結構的一些相關語句


select * from all_tab_comments; --查詢所有用戶的表、視圖等

select * from user_tab_comments; --查詢當前用戶的所有表、視圖等

select * from all_col_comments; --查詢所有用戶的表的列名和注釋

select * from user_col_comments; --查詢當前用戶的表的列名和注釋

select * from all_tab_columns; --查詢所有用戶的表的列的結構信息(沒有備注)

select * from user_tab_columns; --查詢當前戶的表的列的結構信息(沒有備注)

 

--查詢某張表的相信信息(包括列名、數據類型、長度、是否為空、是否主鍵、是否外鍵、備注)
SELECT USER_TAB_COLS.COLUMN_NAME as 列名 , USER_TAB_COLS.DATA_TYPE as 數據類型, USER_TAB_COLS.DATA_LENGTH as 長度, USER_TAB_COLS.NULLABLE as 是否為空, case
when (SELECT col.column_name FROM user_constraints con, user_cons_columns col where con.constraint_name = col.constraint_name and con.constraint_type='P' and col.table_name = '表名' and col.column_name = USER_TAB_COLS.COLUMN_NAME) = USER_TAB_COLS.COLUMN_NAME THEN 'Y'
ELSE 'N'
END
as 是否主鍵,
case when (select count(*) from user_constraints con, user_cons_columns col, (select t2.table_name,t2.column_name,t1.r_constraint_name from user_constraints t1,user_cons_columns t2 where t1.r_constraint_name=t2.constraint_name and t1.table_name='表名') r where con.constraint_name=col.constraint_name and con.r_constraint_name=r.r_constraint_name and con.table_name='表名' and col.column_name = USER_TAB_COLS.COLUMN_NAME) > 0 then 'Y'
else 'N'
END
as 是否外鍵
, user_col_comments.comments as 備注 FROM USER_TAB_COLS inner join user_col_comments on user_col_comments.TABLE_NAME = USER_TAB_COLS.TABLE_NAME and user_col_comments.COLUMN_NAME=USER_TAB_COLS.COLUMN_NAME and USER_TAB_COLS.TABLE_NAME = '表名' ORDER BY USER_TAB_COLS.COLUMN_ID;


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM