Oracle Database --- sequences, indexes, synonyms

- Creating sequence
the Create Sequence deptno_seq
Start with 50
INCREMENT by 10
MAXVALUE 70
Cache 3;

- To facilitate the presentation, creating the same dept table and a table structure deptnew
the Create the Table deptnew
AS
the SELECT * from dept;

- inserting data into the table, and provide data to the primary key column deptno by sequence
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;

- to submit the data to the database inserted
commit;

- modifying sequence
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;

- Delete Sequence
drop sequence deptno_seq;

- Create a separate index
create index idx_ename on emp (ename) ;

- Create composite index
create index idx_deptno_job on emp (deptno, job);

- create a unique index
create unique index idx_dname on dept (dname );

- create a non-unique index
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';

- remove the index
drop index idx_dname;

--system user demo code

- scott user to grant permission to create public synonyms
grant create public synonym to scott;

- scott user to grant permission to create private synonym
grant create synonym to scott;

- Test
- a synonym for private use under the scott user
select * from scott.en;

- the public under the synonyms scott user
select * from dn;

- scott user to grant permission to delete a public synonym
grant drop public synonym to scott;


--scott user demo code

- Create public synonyms
create public synonym dn for scott.deptnew;

- Use public synonym
select * from dn;

- Create private synonyms
create synonym en for scott.empnew;

- the use of private synonym
select * from en;

- See Private synonyms
SELECT and synonym_name, table_owner, table_name
from SYN
WHERE and synonym_name = 'EN';

- View public synonyms
SELECT and synonym_name, table_owner, table_name
from all_synonyms
WHERE and synonym_name = 'the DN';

- Delete public synonym
drop public synonym dn;

- Delete private synonyms
drop synonym en;

 

Guess you like

Origin www.cnblogs.com/xiaomifeng1010/p/11111965.html