Oracle的序列&视图&索引

--oracle的序列的学习
    --创建序列
      --使用 create sequence 序列名
      --特点1:默认开始是没有值的,也就是指针指在了没有值的位置。
      --特点2:序列名.nextval每次执行都会自增一次,默认步长为1
      --特点3:序列名.currval查看当前序列的值。开始是没有的。
      --作用:作为主键使用,动态的获取主键的值,这样新增数据的时候极大的避免了主键冲突
           --使用的是 序列名.nextval作为主键
      --注意:主键是非空唯一就可以,不需要主键的值是连续的值。
           --创建默认序列
             create sequence cc;--创建序列cc
             select cc.currval from dual--查看序列当前值
             select cc.nextval from dual--查看序列的自增后的值。
           --创建自定义序列
              create sequence aa--创建序列
              start with 5      --设置开始位置
              increment by 2    --设置步长
              select aa.currval from dual 
              select aa.nextval from dual
       --创建测试表
           create table teacher(
                tid number(10) primary key,
                tname varchar(100) not null
           )
           insert into teacher values(cc.nextval,'张三');
           insert into teacher values(cc.nextval,'张三');
            
           select * from teacher
    --删除序列
           --drop sequence 序列名
           drop sequence aa
 -------------------------------------------------------------------
 --索引学习:
     --作用:提升查询效率
     --使用索引:
         --创建
           create index 索引名 on 表名(字段名)
         --删除索引
           drop index 索引名
     --特点:
         --显式的创建,隐式的执行
     --注意:
         --oracle会自动给表的主键创建索引。
      
     create index index_teacher_tname on teacher(tname)--创建索引
     drop index index_teacher_tname--删除索引
     select * from teacher where tname='张三'
     select * from teacher where tid=8
--------------------------------------------------------------------
--视图学习:
      --使用视图:
          --创建视图
          create view 视图名 as select 对外提供的内容 from 真实表名
          --删除视图
          drop view 视图名
      --视图特点:
         --特点1:保护真实表,隐藏重要字段的数据。保护数据。
         --特点2:在视图中的操作会映射执行到真实表中
         --特点3:可以手动开启只读模式 使用关键字 with read only
      --注意:视图的创建必须拥有dba权限
      create view stu as select sno,sname,sage from  bjsxt.student
      create view stu2 as select sno,sname,sage from  student with read only 
      drop view stu
      select * from student
      select * from stu
      update stu2 set sname='wollo' where sno=1
      grant dba to bjsxt

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值