oracle查詢表基本信息(索引,外鍵,列等)

oracle中查詢表的信息,包括表名,字段名,字段類型,主鍵,外鍵唯一性約束信息,索引信息查詢SQL如下,希望對大家有所幫助:

1、查詢出所有的用戶表
select * from user_tables 可以查詢出所有的用戶表

select owner,table_name from all_tables; 查詢所有表,包括其他用戶表

通過表名過濾需要將字母作如下處理

select * from user_tables where table_name = upper('表名')

因爲無論你建立表的時候表名名字是大寫還是小寫的,create語句執行通過之後,對應的user_tables表中的table_name字段都會自動變爲大寫字母,所以必須通過內置函數upper將字符串轉化爲大寫字母進行查詢,否則,即使建表語句執行通過之後,通過上面的查詢語句仍然查詢不到對應的記錄。
2、查詢出用戶所有表的索引
select * from user_indexes
3、查詢用戶表的索引(非聚集索引):
select * from user_indexes where uniqueness='NONUNIQUE'
4、查詢用戶表的主鍵(聚集索引):
select * from user_indexes where uniqueness='UNIQUE'
5、查詢表的索引
select t.*,i.index_type from user_ind_columns t,user_indexes i where t.index_name = i.index_name and

t.table_name='NODE'
6、查詢表的主鍵
select cu.* from user_cons_columns cu, user_constraints au where cu.constraint_name = au.constraint_name and

au.constraint_type = 'P' AND cu.table_name = 'NODE'
7、查找表的唯一性約束(包括名稱,構成列):
select column_name from user_cons_columns cu, user_constraints au where cu.constraint_name=au.constraint_name and

cu.table_name='NODE'
8、查找表的外鍵
select * from user_constraints c where c.constraint_type = 'R' and c.table_name='STAFFPOSITION'
查詢外鍵約束的列名:
select * from user_cons_columns cl where cl.constraint_name = 外鍵名稱
查詢引用表的鍵的列名:
select * from user_cons_columns cl where cl.constraint_name = 外鍵引用表的鍵名
9、查詢表的所有列及其屬性
方法一:

select * from user_tab_columns where table_name=upper('表名');

方法二:

select cname,coltype,width from col where tname=upper('表名');;
 
10.查詢一個用戶中存在的過程和函數
select object_name,created,status from user_objects 
where lower(object_type) in ('procedure','function');
 
11.查詢其它角色表的權限
select * from role_tab_privs ;
 
 

查看索引個數和類別

select * from user_indexes where table_name='表名' ;

查看索引被索引的字段


SQL>select * from user_ind_columns where index_name=upper('&index_name');

PS:

查看某表的約束條件


SQL>select constraint_name, constraint_type,search_condition, r_constraint_name 
from user_constraints where table_name = upper('&table_name'); 

SQL>select c.constraint_name,c.constraint_type,cc.column_name 
from user_constraints c,user_cons_columns cc 
where c.owner = upper('&table_owner') and c.table_name = upper('&table_name') 
and c.owner = cc.owner and c.constraint_name = cc.constraint_name 
order by cc.position;

查看視圖的名稱


SQL>select view_name from user_views;

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章