Oracle高级 同义词 索引 序列
2016-10-05 16:05
246 查看
--同义词创建的语法 /* CREATE [OR REPLACE] [PUBLIC] SYNONYM [schema .] synonym FOR [schema .] object [@ dblink]; */
--同义词的优点 --1.安全,隐藏了数据库对象的名称和所有者 --2.提供了对象的公共访问 --3.简化了SQL语句--查询emp表,但是不想让人知道查询的表的真实的名字 grant create synonym to scott ; create synonym ep for emp;--数据字典查看同义词是否创建select * from user_synonyms;select * from ep;--创建一个dept表的同义词 dpcreate or replace synonym dp for dept;select * from user_synonyms;select * from dp;grant create public synonym to scott ;--为emp表创建一个公有的同义词 epcreate or replace public synonym ep for emp;--赋予权限创建同义词grant create [public] synonym to scott ;--同义词执行DMLinsert into dp values(58,'销售','衡阳');--删除同义词的权限grant drop public synonym to scott;--删除同义词drop public synonym ep;--索引
create table student( sid number, sname varchar2(20))
create sequence seq_stu;
--批量插入insert into tableName 子查询;
--生成一条数据select seq_stu.nextval,dbms_random.string('1',10) from dual connect by level <=1;
--生成20条数据select seq_stu.nextval,dbms_random.string('1',10) from dual connect by level <=20;
--生成100W条数据insert into student select seq_stu.nextval,dbms_random.string('1',10) from dual connect by level <=1000000;
select count(1) from student;
--查询id为999999的数据select * from student s where s.sid=999999;--0.156s
--索引创建的语法
--创建索引create index ind_sid on student(sid);
select * from student s where s.sid=999999;--0.141s--数据字典查看索引
select * from user_indexes;
--查看DBA 用户下的索引
select * from dba_indexes where owner='SCOTT';
select * from dba_sequences;
--序列创建的语法
/*CREATE SEQUENCE [schema .] sequence[{ { INCREMENT BY | START WITH }
integer | { MAXVALUE integer | NOMAXVALUE } | { MINVALUE integer | NOMINVALUE } | { CYCLE | NOCYCLE } | { CACHE integer | NOCACHE } | { ORDER | NOORDER } } [ { INCREMENT BY | START WITH } integer | { MAXVALUE integer | NOMAXVALUE } | { MINVALUE integer | NOMINVALUE } | { CYCLE | NOCYCLE } | { CACHE integer | NOCACHE } | { ORDER | NOORDER } ]...];*/
--创建一个序列 seq_test 起始值为1000 最大值为1004 步长为1的 不循环 缓存为20 的序列
create sequence seq_test start with 1000 maxvalue 1004 increment by 1 nocycle cache 20;
--怎么查看序列是否创建成功
--1.plsql左侧视图查看
--2.使用数据字典
select * from user_sequences;
--查看序列的值
select seq_test.nextval from dual;
--查看序列的下一个值
select seq_test.currval from dual;--序列当前值
create sequence seq_test1 start with 1000 maxvalue 1004 increment by 1 cycle cache 20;select seq_test1.nextval from dual;
相关文章推荐
- Oracle笔记 五、创建表、约束、视图、索引、序列、同义词、表空间
- Oracle学习笔记之六(DDL:表、索引、视图、同义词、序列操作相关SQL)
- ’;oracle表,视图,索引,序列,同义词等基本操作总结(作者:西西)
- oracle_序列、索引、同义词
- Oracle笔记 五、创建表、约束、视图、索引、序列、同义词、表空间
- 【数据库】[oracle]表,视图,索引,序列,同义词等操作集合
- Oracle笔记 五、创建表、约束、视图、索引、序列、同义词、表空间
- oracle 中的视图,索引,序列及同义词数据字典
- oracle 中的视图,索引,序列及同义词数据字典
- Oracle笔记 五、创建表、约束、视图、索引、序列、同义词、表空间
- Oracle笔记 五、创建表、约束、视图、索引、序列、同义词、表空间(转)
- Oracle笔记 五、创建表、约束、视图、索引、序列、同义词、表空间
- oracle 数据库模式对象,索引,序列,同义词,查看用户拥有的表,聚簇,数据库链接
- Oracle同义词 序列 索引 异常处理 示例分析
- Oracle笔记 五、创建表、约束、视图、索引、序列、同义词、表空间
- Oracle笔记 五、创建表、约束、视图、索引、序列、同义词、表空间
- Oracle笔记 五、创建表、约束、视图、索引、序列、同义词、表空间
- oracle 数据库模式对象,索引,序列,同义词,查看用户拥有的表,聚簇,数据库链接
- Oracle笔记 五、创建表、约束、视图、索引、序列、同义词、表空间
- Oracle笔记 五、创建表、约束、视图、索引、序列、同义词、表空间