oracle資料庫為表字段建立索引的方法

2021-09-04 04:33:53 字數 3514 閱讀 1698

目錄

建立表字段索引方法

1、查詢出所有的使用者表

2、查詢出使用者所有表的索引

3、查詢使用者表的索引(非聚集索引):

4、查詢使用者表的主鍵(聚集索引):

5、查詢表的索引

6、查詢表的主鍵

7、查詢表的唯一性約束(包括名稱,構成列):

8、查詢表的外來鍵

查詢外來鍵約束的列名:

查詢引用表的鍵的列名:

9、查詢表的所有列及其屬性

方法一:

方法二:

10.查詢乙個使用者中存在的過程和函式

11.查詢其它角色表的許可權

12.檢視索引個數和類別

檢視索引被索引的字段

檢視某錶的約束條件

檢視檢視的名稱

語法sql:create index 索引名稱 on 表名 (欄位名稱);

例項sql:

create index info_task_id on sended_info (task_id);

-- info_task_id :索引名字自己起得

--sended_info :資料庫表名稱

--task_id:資料庫欄位名稱

查詢sql:

select t.*  from sended_info t;
查詢指定表的索引

這裡t.table_name輸入的是指定表名字,必須都是大寫。

select t.*,i.index_type from user_ind_columns t,user_indexes i where t.index_name = i.index_name and t.table_name='es_third_party_order_reltn';
查詢結果:

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將字串轉化為大寫字母進行查詢,否則,即使建表語句執行通過之後,通過上面的查詢語句仍然查詢不到對應的記錄。

select * from user_indexes
select * from user_indexes where uniqueness='nonunique'
select * from user_indexes where uniqueness='unique'
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'
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'
select column_name from user_cons_columns cu, user_constraints au where cu.constraint_name=au.constraint_name and cu.table_name='node'
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 = 外來鍵引用表的鍵名
select * from user_tab_columns where table_name=upper('表名');
select cname,coltype,width from col where tname=upper('表名');
select object_name,created,status from user_objects 

where lower(object_type) in ('procedure','function');

select * from role_tab_privs ;
select * from user_indexes where table_name='表名' ;
select * from user_ind_columns where index_name=upper('&index_name');
select constraint_name, constraint_type,search_condition, r_constraint_name 

from user_constraints where table_name = upper('&table_name');

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;

select view_name from user_views;
參考部落格:

修改Oracle資料庫表字段型別

修改user表的name欄位型別從varchar2改為clob 1.新增乙個備份字段 alert table user add name back clob 2.複製name的值到備份欄位name back update user set name back name 3.刪除原來的字段user a...

資料庫表字段介紹

相應字段 categoryid 型別id categoryname 型別名 description 型別說明 picture 產品樣本 customercustomerdemo 客戶型別表1 相應字段 customerid 客戶id customertypeid 客戶型別id customerdem...

Oracle資料庫查詢所有表 欄位和注釋

1.表獲取 對於獲取表資訊,可供選擇的表有 select from user tables 當前使用者的表 select from all tables 所有使用者的表 select from dba tables 包括系統表 select from dba tables where owner t...