• 创建和管理表


                                
     
     
    /*************创建表*****************/
    create table student
    (
    stu_code  varchar2(10) constraint pk_stu_code  primary key
                                  using index tablespace indx,
    stu_name varchar2(20),
    stu_sex char(1) check(stu_sex in('f','m'))
    )
    tablespace users
    pctfree  30   
    pctused 40
    storage
    (
    initial  40k
    next     80k
    minextents 2
    maxextents 10
    pctincrease  50
    )
    initrans 2
    maxtrans 50
    logging
    parallel
    /*
      注解:
           pctfree:空闲因子
           pctused:复用因子
           storage参数继承和重载表空间的参数。不写默认使用表空间的参数设置。
           initrans:预留可以访问事务的块数(保存事务ID号)
           maxtrans:最大可访问事务的块数.
           OLTP类型:initrans   10
                     maxtrans   255
           DSS类型: initrans   1
                     maxtrans   15
           最小为1,不能设置为0。
           buffer_spool keep|recycle|defaull
           keep:表示常驻内存区(一般不用)
           recycle:表示临时或即时清除区
           defaull:默认存放
    */
     
    /************插入数据******************/
    insert into student values(0001,'呵呵','f');
    insert into student values(0002,'细心','m');
    insert into student values(0003,'邪恶','m');
    insert into student values(0004,'白事实','m');
    insert into student values(0005,'白代数ff ','f');
    insert into student values(0006,'白但厂tsfdgdssd','f');
    column stu_sex format a3;
    select * from student;
     
    STU_CODE   STU_NAME             STU
    ---------- -------------------- ---
    1          呵呵                 f
    2          细心                 m
    3          邪恶                 m
    4          白事实               m
    5          白代数ff             f
    6          白但厂tsfdgdssd      f
     

    /*修改该行的占用的位置大小为7格***********/
    column stu_sex format a7;
     
    STU_CODE   STU_NAME             STU_SEX
    ---------- -------------------- -------
    1          呵呵                 f
    2          细心                 m
    3          邪恶                 m
    4          白事实               m
    5          白代数ff             f
    6          白但厂tsfdgdssd      f
     

    /*************标记列为不可用状态(该行将不被显示)*****************/
    alter table student set unused (stu_sex);
     

    /************** 查询标记列****************/
     select * from dba_unused_col_tabs;
     
    /*************删除所有标记列(不能回滚)*************/
    alter table student drop unused columns;
     

    /*************删除单一标记列(不能回滚)*************/
     
    alter table student drop unused(stu_sex);
     

    /***********段平移(从表空间开始修改存储参数)**************/
    alter table student move
    tablespace tools
     
    /*****************表的删除************************/
    drop table student cascade constraints 
    cascade constraints :强制删除本表及其他表中的相关外部约束.(FK....)
     
    /***************表的内容删除(保留MINEXTENTS)**************/
     truncate table student drop storage
     
    /*******表的内容删除(删除所有的区)******/
    truncate table student resume storage
     
    /***********约束的禁用*************/
    alter table student disable constraint pk_stu_code;
     
    /***********约束的激活*************/
    alter table student enable constraint pk_stu_code;
     
    /****************************查询违反约束的记录**********************************/
    运行下面的SQL:
    create table exceptions(row_id rowid,
                     owner varchar2(30),
                     table_name varchar2(30),
              constraint varchar2(30));
     
    /****执行约束管理语句****/
    alter table student enable constraint pk_stu_code exceptions into exceptions;
     
    /****查询约束管理的记录****/
    select * from exceptions
    /****执行结果****/
     
    ROW_ID             OWNER                          TABLE_NAME
    ------------------ ------------------------------ ------------------------------
    CONSTRAINT
    ------------------------------
    AAAH2XAAIAAAAASAAG SYSTEM                         STUDENT
    PK_STU_CODE
     
    AAAH2XAAIAAAAASAAA SYSTEM                         STUDENT
    PK_STU_CODE
     
    /************************************表分区(创建表时分区)**********************************/
    分类: 范围分区:用一个具有明显特性的字段做为分区标准
          列表分区:枚举(例如性别)
          散列分区:不具有范围和枚举特性的分区.(系统调配)又称为哈希分区
          复合分区
    /*******范围分区******/
    partition by range (stu_code)
    (
    partition pt_stu_01 values less than('100') tablespace tools pctfree 20  pctused 30,
    partition pt_stu_02 values less than('200') tablespace users pctfree 20  pctused 30,
    partition pt_stu_03 values less than(maxvalue) tablespace system pctfree 5
    )
     
    /*****列表分区***********/
    partition by list (stu_sex)
    (
    partition pt_stu_03 values ('f'),
    partition pt_stu_04 values ('m')
    )
     
    /*****散列分区*********/
    partition by hash (stu_code)
    (
    partition pt_stu_05 tablespace users,
    partition pt_stu_06 tablespace tools
    )
     
    /*****新建分区(只能在已有同一类型的分区上添加)*****/
    alter table student add partition pt_stu_07
     
    /*****移动分区******/
    alter table student move partition pt_stu_08 tablespace users
     
    /*****删除分区(散列不能删除)****/
    alter table student drop partition pt_stu_03
     
    /****拆分分区(散列不能拆分)****/
    alter table student split partition pt_stu_01 at 300 into pt_stu_10
     
    错误/******合并分区(散列不能合并)************/
    alter table student merge partition(pt_stu_01, pt_stu_02) into pt_stu_11
     
     
     
     
     
     
  • 相关阅读:
    ueditor 后端配置项没有正常加载,上传插件不能正常使用 UTF8 PHP
    dedecms 后台栏目全部展开 包括三级栏目
    修改DedeCMS图片上传路径命名规则的具体方法步骤
    dedecms织梦副栏目名称和链接调用
    当位于顶级栏目显示下级栏目,当位于二级栏目显示同级栏目,当位于三级目录,显示上级栏目
    织梦多个栏目arclist调用副栏目不显示的解决办法
    PL/SQL连接64位Oracle配置方法
    U盘分区之后如何恢复
    Myeclipse 的使用随笔
    eclipse和myeclipse的差别问题
  • 原文地址:https://www.cnblogs.com/wenjl520/p/1445764.html
Copyright © 2020-2023  润新知