索引的常用操作
-- 创建主键索引alter table table_name add constraint pk_name primary key(table_id);-- 创建普通索引create index index_name on table_name (table_colounm_name);-- 删除全局主键索引alter table table_name DROP constraint index_name ;-- 索引重建alter index ipk_name REBUILD ;-- 删除索引DROP INDEX index_name;-- 创建复合索引CREATE INDEX Index_name ON table_name(colunm_1,colunm_2);-- 重建索引alter index index_name rebuild;-- 重建分区索引alter index index_name rebuild partition partition_name;-- 在线增加分区索引 `online`,不影响其他DML操作,否则可能会阻塞DMLalter table table_name add (constraint ipx_name primary key(ID,insert_tm) using index local) online;-- 创建分区索引create index index_name on table_name (table_colounm_name) local;
删除自动生成的主键索引
declarev_cursor integer;v_sql varchar2(500);BEGINFOR RX IN (select index_name from user_indexes WHERE table_name = 'table_name') LOOPv_cursor:=dbms_sql.open_cursor;v_sql:='alter table table_name drop constraint ' || RX.INDEX_NAME;dbms_sql.parse(v_cursor, v_sql, dbms_sql.v7);dbms_sql.close_cursor(v_cursor);END LOOP;end;/