Oracle索引使用详解

-- 索引:普通索引、唯一索引、复合索引

           create index XX on tableNamep[colName]

使用索引的好处,就是检索效率快,和使用主键、rowid(物理地址) 差不多,使用主键检索的实质就是使用ROWID(物理地址)

eg:
     create unique index 索引名 on tablename(列名)
     create index index_test_ah on t_indextest(id,name);
     select * from t_indextest where id = 777580 and name = 'aa7775

-- 索引:普通索引、唯一索引、复合索引
create index XX on tableNamep[colName]
-- 创建一个普通索引
-- 创建索引的好处,就是检索效率快,和使用主键、rowid(物理地址) 差不多,使用主键检索的实质就是使用ROWID(物理地址)
create index index_orders_name on t_owners(name);

create table T_INDEXTEST (ID NUMBER,NAME1 VARCHAR2(30),NAME2 VARCHAR2(30),NAME3 VARCHAR2(30),NAME4 VARCHAR2(30),NAME5 VARCHAR2(30));
begin
  for x in 1..1000000
    loop
      insert into T_INDEXTEST values (x,'aa'||x,'bb'||x,'cc'||x,'dd'||x,'ee'||x);
    end loop;
    commit;
end;

create index index_test on T_INDEXTEST(name);

select * from t_indextest where id = 777580
select * from t_indextest where name = 'aa777580'
select rowid,t.* from t_indextest t where name = 'aa777580'
select * from t_indextest where rowid = 'AAAM3lAAGAAAAmOAFs'

-- 创建唯一索引
create unique index 索引名 on tablename(列名)
create index index_test_ah on t_indextest(id,name);
drop index index_test_ah
select * from t_indextest where id = 777580 and name = 'aa777580'


select * from t_indextest where name1='aa777777' and name2='bb777777' and name3='cc777777'
create index index_indextest_aa on t_indextest(name1,name2,name3)


select * from t_account where year = '2012' and month = '01' and ownerid = 1;

猜你喜欢

转载自blog.csdn.net/li_tiantian/article/details/81585915
今日推荐