zoukankan      html  css  js  c++  java
  • [每日一题] OCP1z0-047 :2013-07-15 drop column


    如下实验:

    gyj@OCM> Create table emp(

      2    Empno     number(4)    not null,

      3    First_name  varchar2(20),

      4    Last_name  varchar2(20),

      5    Salary      number(10,2),

      6    Deptno     number(2)

      7  );

    Table created.

    gyj@OCM> insertinto emp values(100,'yijun','guo',35000,1);

    1 row created.

    gyj@OCM>commit;

    Commit complete.

    gyj@OCM> altertable emp drop column first_name; --有数据也能被删除!排除答案A

    Table altered.

    gyj@OCM> altertable emp drop column Empno;

    Table altered.

    gyj@OCM> altertable emp drop column last_name;

    Table altered.

    gyj@OCM> altertable emp drop column salary;

    Table altered.

    gyj@OCM> altertable emp drop column deptno;

    alter table empdrop column deptno

    *

    ERROR at line 1:

    ORA-12983: cannotdrop all columns in a table  ----验证了答案B是对的

    SET UNUSED Clause   ---官方解释,排除答案C

    Specify SET UNUSED to mark one or more columns asunused. Specifying this clause does not actually remove the target columns fromeach row in the table. That is, it does not restore the disk space used bythese columns. Therefore, the response time is faster than when you execute theDROP clause.

    清楚掉字典信息(撤消存储空间),不可恢复。

    不要马上drop column,应该先setunusedcolumn无法使用,避开系统尖峰时间再来处理删除栏位里的资料,要注意的是一但你set unused column,这个栏位是无法再回复使用的。

    gyj@OCM> altertable emp add first_name varchar2(10);

     

    Table altered.

     

    gyj@OCM> select *from emp;

     

        DEPTNO FIRST_NAME

    ---------- ----------

             1

     

    gyj@OCM> updateemp set first_name='yijun';

     

    1 row updated.

     

    gyj@OCM> commit;

     

    Commit complete.

     

    gyj@OCM> ALTERTABLE emp SET UNUSED (first_name);

     

    Table altered.

     

    gyj@OCM> altertable emp drop unused column;

     

    Table altered.

     

    gyj@OCM> select *from emp;

     

        DEPTNO

    ----------

             1

     

    gyj@OCM> alter table emp add first_name varchar2(10);

    Table altered.

    gyj@OCM> select * from emp

      2 ;

        DEPTNO FIRST_NAME

    ---------- ----------

             1

    gyj@OCM> update emp set first_name='yijun';

    1 row updated.

    gyj@OCM> commit;

    Commit complete.

    gyj@OCM> alter table emp add primary key(deptno,first_name);

    Table altered.

    yj@OCM> alter table emp drop column first_name;

    alter table emp drop column first_name

                                *

    ERROR at line 1:

    ORA-12991: column is referenced in a multi-column constraint

    gyj@OCM> alter table emp drop column first_name cascade constraints;

    Table altered.

    ------验证了答案D是对的

    答案:BD


  • 相关阅读:
    基于51单片机数码管显示经ADC0808转化1K电位器分压5V模拟量为数字量的项目工程
    基于51单片机数码管显示经ADC0808转化1K电位器分压5V模拟量为0V-5V数字量的项目工程
    浅谈移动端过长文本溢出显示省略号的实现方案
    浅谈自动化测试
    Tomcat 优雅关闭之路
    InnoDB 事务加锁分析
    Tomcat 9.0.26 高并发场景下DeadLock问题排查与修复
    Kotlin 协程真的比 Java 线程更高效吗?
    Spark 数据倾斜及其解决方案
    大数据平台架构设计探究
  • 原文地址:https://www.cnblogs.com/jiangu66/p/3192096.html
Copyright © 2011-2022 走看看