oracle查詢表資訊(索引,外來鍵,列

2021-06-26 11:53:43 字數 2649 閱讀 1831

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;

oracle查詢表資訊(索引,外來鍵,列等)

oracle中查詢表的資訊,包括表名,欄位名,字段型別,主鍵,外來鍵唯一性約束資訊,索引資訊查詢sql如下,希望對大家有所幫助 1 查詢出所有的使用者表 select from user tables 可以查詢出所有的使用者表 select owner,table name from all tab...

oracle查詢表資訊(索引,外來鍵,列等)

oracle查詢表資訊 索引,外來鍵,列等 oracle中查詢表的資訊,包括表名,欄位名,字段型別,主鍵,外來鍵唯一性約束資訊,索引資訊查詢sql如下,希望對大家有所幫助 1 查詢出所有的使用者表 select from user tables 可以查詢出所有的使用者表 查詢表的列數 select ...

oracle查詢表基本資訊(索引,外來鍵,列等)

oracle中查詢表的資訊,包括表名,欄位名,字段型別,主鍵,外來鍵唯一性約束資訊,索引資訊查詢sql如下,希望對大家有所幫助 1 查詢出所有的使用者表 select from user tables 可以查詢出所有的使用者表 select owner,table name from all tab...