–创建序列
create sequence deptno_seq
start with 50
increment by 10
maxvalue 70
cache 3;
–为了方便演示,创建了一个和dept表结构相同的deptnew表
create table deptnew
as
select * from dept;
–向表中插入数据,并通过序列给主键列deptno提供数据
insert into deptnew(deptno,dname,loc)values(deptno_seq.nextval,’test_dname’,’test_loc’);
select * from deptnew;
–currval
select deptno_seq.currval from dual;
–查询序列
select sequence_name, min_value, max_value, increment_by, cycle_flag, cache_size, last_number
from user_sequences;
–向数据库提交插入的数据
commit;
–修改序列
alter sequence deptno_seq
maxvalue 90;
–测试
insert into deptnew(deptno,dname,loc)values(deptno_seq.nextval,’test_dname’,’test_loc’);
select * from deptnew;
rollback;
insert into deptnew(deptno,dname,loc)values(deptno_seq.nextval,’test_dname’,’test_loc’);
select * from deptnew;
commit;
–删除序列
drop sequence deptno_seq;
–创建单列索引
create index idx_ename on emp(ename);
–创建复合索引
create index idx_deptno_job on emp(deptno,job);
–创建唯一索引
create unique index idx_dname on dept(dname);
–创建非唯一索引
create index idx_job on emp(job);
–查询索引
select uic.index_name, uic.column_name, uic.column_position, ui.uniqueness
from user_indexes ui, user_ind_columns uic
where uic.index_name = ui.index_name and ui.table_name=’emp’;
–删除索引
drop index idx_dname;
–system用户的演示代码
–给scott用户授予创建公共同义词的权限
grant create public synonym to scott;
–给scott用户授予创建私有同义词的权限
grant create synonym to scott;
–测试
–使用scott用户下的私有同义词
select * from scott.en;
–使用scott用户下的公共同义词
select * from dn;
–给scott用户授予删除公共同义词的权限
grant drop public synonym to scott;
–scott用户的演示代码
–创建公共同义词
create public synonym dn for scott.deptnew;
–使用公共同义词
select * from dn;
–创建私有同义词
create synonym en for scott.empnew;
–使用私有同义词
select * from en;
–查看私有同义词
select synonym_name,table_owner,table_name
from syn
where synonym_name = ‘en’;
–查看公共同义词
select synonym_name,table_owner,table_name
from all_synonyms
where synonym_name = ‘dn’;
–删除公共同义词
drop public synonym dn;
–删除私有同义词
drop synonym en;