select a.TABLE_NAME as "TableName", case when (select count(*) from user_views v where v.VIEW_NAME =a.TABLE_NAME )>0 then 'V' else 'U'end as "TableType", a.COLUMN_NAME as "ColumnName", A.COLUMN_ID as "ColumnIndex", a.DATA_TYPE as "DataType", case when a.DATA_TYPE = 'NUMBER' then case when a.Data_Precision is null then a.Data_Length else a.Data_Precision end else a.Data_Length end as "Length", case when a.nullable = 'N' then '0' else '1' end as "IsNullable", b.comments as "Description", case when (select count(*) from user_cons_columns c where c.table_name=a.TABLE_NAME and c.column_name=a.COLUMN_NAME and c.constraint_name= (select d.constraint_name from user_constraints d where d.table_name=c.table_name and d.constraint_type ='P') )>0 then '1' else '0'end as "IsPK" from USER_TAB_COLS a, sys.user_col_comments b where a.table_name = b.table_name and b.COLUMN_NAME = a.COLUMN_NAME order by a.TABLE_NAME, a.COLUMN_ID
查詢表的所有列及其屬性:
select t.*,c.COMMENTS
from user_tab_columns t,user_col_comments c
where t.table_name = c.table_name and t.column_name = c.column_name and t.table_name = women;
查找表的主鍵:
select cu.*
from user_cons_columns cu, user_constraints au
where cu.constraint_name = au.constraint_name and au.constraint_type = 'P' and au.table_name = women;
查找表的外鍵(包括名稱,引用表的表名和對應的鍵名,下面是分成多步查詢):
select * from user_constraints c where c.constraint_type = 'R' and c.table_name = women
查詢外鍵約束的列名:
select * from user_cons_columns cl where cl.constraint_name = 外鍵名稱;
查詢引用表的鍵的列名:
select * from user_cons_columns cl where cl.constraint_name = 外鍵引用表的鍵名;
方法一:
在Oracle SQL Plus輸入以下命令
DESC 表名;
方法二:
用【PLSQL Developer】工具,右擊表名【編輯】選擇【列】
或【PLSQL Developer】命令窗口輸入:DESC 表名;