当前位置:Gxlcms > 数据库问题 > oracle创建序列&索引&视图

oracle创建序列&索引&视图

时间:2021-07-01 10:21:17 帮助过:32人阅读

--oracle的序列的学习 2 --创建序列 3 --使用 create sequence 序列名 4 --特点1:默认开始是没有值的,也就是指针指在了没有值的位置。 5 --特点2:序列名.nextval每次执行都会自增一次,默认步长为1 6 --特点3:序列名.currval查看当前序列的值。开始是没有的。 7 --作用:作为主键使用,动态的获取之间的值,这样新增数据的时候极大的避免了主键冲突 8 --使用的是 序列名.nextval作为主键 9 --注意:主键是非空唯一就可以,不需要主键的值是连续的值。 10 --创建默认序列 11 create sequence cc;--创建序列cc 12 select cc.currval from dual--查看序列当前值 13 select cc.nextval from dual--查看序列的自增后的值。 14 --创建自定义序列 15 create sequence aa--创建序列 16 start with 5 --设置开始位置 17 increment by 2 --设置步长 18 cache 10 --缓存10 19 select aa.currval from dual 20 select aa.nextval from dual 21 --创建测试表 22 create table teacher( 23 tid number(10) primary key, 24 tname varchar(100) not null 25 ) 26 insert into teacher values(cc.nextval,张三); 27 insert into teacher values(cc.nextval,张三); 28 29 select * from teacher 30 --删除序列 31 --drop sequence 序列名 32 drop sequence aa View Code

 

索引

技术图片
 1      --作用:提升查询效率
 2      --使用索引:
 3          --创建
 4            create index 索引名 on 表名(字段名)
 5          --删除索引
 6            drop index 索引名
 7      --特点:
 8          --显示的创建,隐式的执行
 9      --注意:
10          --oracle会自动给表的主键创建索引。
11       
12      create index index_teacher_tname on teacher(tname)--创建索引
13      drop index index_teacher_tname--删除索引
14      select * from teacher where tname=张三
15      select * from teacher where tid=8
View Code

 

视图

技术图片
 1 --视图学习:
 2       --使用视图:
 3           --创建视图
 4           create view 视图名 as select 对外提供的内容 from 真实表名
 5           --删除视图
 6           drop view 视图名
 7       --视图特点:
 8          --特点1:保护真实表,隐藏重要字段的数据。保护数据。
 9          --特点2:在视图中的操作会映射执行到真实表中
10          --特点3:可以手动开启只读模式 使用关键字 with read only
11       --注意:视图的创建必须拥有dba权限
12       create view stu as select sno,sname,sage from  bjsxt.student
13       create view stu2 as select sno,sname,sage from  student with read only 
14       drop view stu
15       select * from student
16       select * from stu
17       update stu2 set sname=wollo where sno=1
18       grant dba to bjsxt
View Code

 

oracle创建序列&索引&视图

标签:保护   备份   read   其他   oracle学习   rom   定义   nbsp   rem   

人气教程排行