序列,同义词,索引

--------------------序列(产生连续的值)---------------------------
--创建简单序列
create sequence seq_test;
--查询序列的下一个值--
select seq_test.nextval from dual
--查询序列的当前值--
select seq_test.currval from dual
--有最大值的非循环序列--
create sequence seq_test1
maxvalue 20;
select seq_test1.nextval from dual;

create sequence seq_test2
increment by 10
start with 10
maxvalue 100;
select seq_test2.nextval from dual;
--循环序列--
create sequence seq_test4
increment by 10
start with 10
minvalue 10
maxvalue 210
cycle
cache 5;
select seq_test4.nextval from dual;
--一次缓存的数有多少,cache值*增长值--
--一次云焕的值不能小于一次缓存的数(在循环时)--
--------------------同义词(别名)---------------------------
--创建私有同义词(别的用户用不了)--
create synonym owner for t_owners;
select*from owner
--创建公有同义词--
create public synonym owners2 for t_owners
select*from owners2
--------------------索引(提高查询效率)---------------------------
--索引(用经常用的列建立索引,可以提高速度)--
create index index_owners_name on t_owners(name);
select*from t_owners where name='张哲'
--性能测试(创建一个表,插入100万条记录)--
create table t_indextest(id number,name varchar2(30))
begin
for x in 1..1000000
loop
insert into t_indextest values(x,'aa'||x);
end loop;
commit;
end;
create index index_test on t_indextest(name);
select*from t_indextest where id=765432;
select*from t_indextest where name='aa765432';
--唯一索引(该列值不能重复)--
create unique index index_owners_meter on t_owners(watermeter);
--复合索引--
select*from t_owners where addressid=1 and housenumber='1-3'
create index index_owners_ah on t_owners(addressid,housenumber);
--反向键索引(reverse)(值是连续的时候)--
--位图索引(bitmap)(可能值是有限的时候)--

posted @ 2021-04-25 23:14  zfxd  阅读(104)  评论(0)    收藏  举报