当前位置 博文首页 > S_zhangmin的博客:ORACLE sql走过的一些坑

    S_zhangmin的博客:ORACLE sql走过的一些坑

    作者:[db:作者] 时间:2021-09-19 16:14

    1.创建表

    注意:

    constraint pk_表名 primary key (主键);

    constraint fk_表名_外键?foreign key (外键);

    ? ? ?reference 外建表名 (主键);

    2.创建触发器

    create or replace trigger 表名_BIU

    ? ? before insert or update on 表名

    ? ? for each row?

    下面接规则

    注意 两个或以上的触发器是要用 '/' 隔开。

    3. 插入数据

    insert into 表名 (需插入字段名1,字段名2,……) values (字段值,字段值,……)

    注意 当该表外接了一个表A时,需要现在表A中输入数据。

    4.建立索引

    官方给出 索引的主要作用

    1. To enforce unique values within a column
    2. To improve data access performance
    3. To prevent lock escalation when updating rows of tables that use declarative referential integrity

    1. 在列中强制使用唯一值
    2. 提高数据访问性能
    3. 在更新使用声明性参照完整性的表行时防止锁定升级

    用法:

    create unique index 自定义的名称? on 需建立索引的表 (对应索引的字段名)

    例:create unique index employee_ename_idx on employees (name)

    5.查询数据

    select 你需要的字段(可以自己取名) from 指定的数据表

    存在多表操作或有限定操作,使用where?

    6.添加列

    alter table 表名 add 字段 字段类型(数量)

    7.查询oracle数据字典

    oracle 自带 user_tables 里面字段很多 都是表的信息

    一般可以看表名、索引信息、索引位置等等……

    user_tab_columns

    user_ind_columns

    可以自己试一下。

    select * from user_tab_columns

    8.更新数据

    update 数据表 set 字段名 = 字段值;

    有具体要求,搭配where检索

    9.综合查询

    select?

    (主要是用一些函数,实现搜索或是处理后输出)

    from 表名;
    10.压缩数据

    alter table 表名 compress for oltp;

    11.删除数据

    delete from 表名

    where 字段名 = '字段值';

    12.删除表

    drop table 表名?cascade constraints;

    注意:这里与创建表有一点不同 constraint 要加s。

    主要是能消除外接表的信息;

    13.恢复表

    两步:

    1.检查是否可以被恢复

    select object_name,?
    ? ? ? ?original_name,?
    ? ? ? ?type,?
    ? ? ? ?can_undrop,?
    ? ? ? ?can_purge
    from recyclebin;

    查看自带的recyclebin。

    或有一个自带的是否可恢复的状态can_undrop,?

    2.flashback table 表名 to before drop;

    实现恢复数据。

    ?

    ?

    cs
    下一篇:没有了