• 不得不会的Oracle数据库知识点(三)


    目录

    锁和数据库对象

    1.锁

    2.数据库对象


    锁和数据库对象

    1.锁

    数据库用来控制共享资源并发访问的机制。

    锁的类型:行级锁,表级锁。

    行级锁:对正在被修改的行进行锁定。行级锁也被称之为排他锁。

    在使用下列语句时,Oracle会自动应用行级锁:

    insert,update,delete,select…… for update

    select……for update允许用户一次锁定多条记录进行更新。

    使用commit or rollback释放锁。

    表级锁:

    lock table user_tbl in mode mode;

    表级锁类型:

    行共享 row share

    行排他 row exclusive

    共享 share

    共享行排他 share row exclusive

    排他 exclusive

    死锁:两个或两个以上的事务相互等待对方释放资源,从而形成死锁

    2.数据库对象

    oracle数据库对象又称模式对象

    数据库对象是逻辑结构的集合,最基本的数据库对象是表

    数据库对象:

    表,序列,视图,索引。

    序列用于生成唯一,连续序号的对象。

    创建语法:

    1. create sequence user_id_seq
    2. start with 1000
    3. increment by 1
    4. maxvalue 2000
    5. minvalue 1000
    6. nocycle
    7. cache 1000;--指定内存中预先分配的序号

    访问序列:

    1. select user_id_seq.currval from dual;
    2. select user_id-seq.nextval from dual;

    更改删除序列:

    1. alter sequence user_id_seq maxvalue 10000;--不能修改其start with 值
    2. drop sequence user_id_seq;

    在Hibernate中访问序列:

    1. <generator class="sequence">
    2. <param name="sequence">     
    3. user_id_seq
    4. </param>
    5. </generator>

    视图

    以经过定制的方式显示来自一个或多个表的数据

    创建视图:

    1. create or replace view
    2. user_tbl_view (vid,vname,vage)
    3. as select id,user_name,age from user_tbl
    4. [with check option]|[with read only];

    创建带有错误的视图:

    1. create force view user_tbl_force_view as
    2. select * from user_table;--此时user_table可以不存在

    创建外联接视图:

    1. create view user_stu_view as
    2. select u.id,u.user_name,u.password,s.ddress
    3. from user_tbl u,stu_tbl s
    4. where u.s_id(+)=s.id;--哪一方带有(+),哪一方就是次要的

    删除视图:

    drop user_stu_view;

    索引用于提高SQL语句执行的性能

    索引类型:

    唯一索引,位图索引,组合索引,基于函数的索引,反向键索引

    创建标准索引:

    create index user_id_index on user_tbl(id) tablespace schooltbs;

    重建索引:

    alter index user_id_index rebuild;

    删除索引:

    drop index user_id_index;

    创建唯一索引:

    create unique index user_id_index on user_tbl(id);

    创建组合索引:

    create index name_pass_index on user_tbl(user_name,password);

    创建反向键索引:

    create index user_id_index on user_tbl(id) reverse;

  • 相关阅读:
    口袋参谋:99.9999%商家都在用的,下拉词搜索工具!
    面向对象编程思维(软件工程)
    CMSIS-RTOS2简介
    copy\while-python(day6)
    OS10 - 计数器和警报(1)
    GDB/MI断点信息
    等差数列 马蹄集
    Mybatis按年月日时分秒查询,MySQL年月日时分秒查询
    【Vue】 toRef以及context参数(1)
    自然语言处理nlp小姜机器人(闲聊) nlp_xiaojiang-996station GitHub鉴赏官
  • 原文地址:https://blog.csdn.net/xiejiachao/article/details/125196736