有疑问可以去itpub讨论:http://www.itpub.net/thread-1804872-1-1.html

对于alter table setunused的用法,查官方文档:

alter_table::=

column_clauses::=

drop_column_clause ::=

SET UNUSED Clause

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.

You can view all tables with columns marked UNUSED in the data dictionary views USER_UNUSED_COL_TABS, DBA_UNUSED_COL_TABS, and ALL_UNUSED_COL_TABS.

Unused columns are treated as if they were dropped, even though theircolumn data remains in the table rows. After a column has been marked UNUSED, you have no access to that column. A SELECT * query will not retrieve data from unusedcolumns. In addition, the names and types of columns marked UNUSED will not be displayed during a DESCRIBE, and you can add to the table a new column with the same name as an unusedcolumn.

对上面的题,先做实验,看测试结果,一一验证:

1、在gyj用户下创建一个表:

gyj@OCM> create table emp as select employee_id,first_name,manager_idfrom hr.employees;

Table created.

2、 创建一个公共的同义词e

gyj@OCM> create public synonym e for emp;

Synonym created.

gyj@OCM> select * from e;

EMPLOYEE_ID FIRST_NAME          MANAGER_ID

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

198 Donald                      124

199 Douglas                     124

省略结果。。。。。

3、创建一个私有的同义词m

gyj@OCM> create  synonym m foremp;

Synonym created.

gyj@OCM> select * from m;

EMPLOYEE_ID FIRST_NAME          MANAGER_ID

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

198 Donald                      124

199 Douglas                     124

省略结果。。。。。

4、在字段manager_id列上建一个条件check约束

gyj@OCM> alter table emp add(constraint c_emp_manageridcheck(manager_id>=100));

Table altered.

gyj@OCM> select CONSTRAINT_NAME from user_constraints wheretable_name='EMP';

CONSTRAINT_NAME

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

C_EMP_MANAGERID

gyj@OCM> insert into emp values(500,'guoyJoe',99);

insert into emp values(500,'guoyJoe',99)

*

ERROR at line 1:

ORA-02290: check constraint (GYJ.C_EMP_MANAGERID) violated

报错是说明不满足约束,说明约束起作用了

5、创建一个视图v_emp

gyj@OCM> create view v_emp as select *  from emp;

View created.

gyj@OCM> select * from v_emp;

EMPLOYEE_ID FIRST_NAME          MANAGER_ID

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

198 Donald                      124

199 Douglas                     124

省略结果。。。

6、在列manager_id上创建一个索引

gyj@OCM> create index idx_id on emp(manager_id);

Index created.

gyj@OCM> select index_name from user_indexes where table_name='EMP';

INDEX_NAME

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

IDX_ID

好,我们按上面的题意,开始做alter table set unused操作:

gyj@OCM> altertable emp set unused ( manager_id);

Table altered.

同义词在数据字典中还能用,无需重建,所以答案A错

gyj@OCM> select OBJECT_NAME  FROM user_objects where object_type='SYNONYM'AND OBJECT_NAME IN('M','E');

OBJECT_NAME

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

M

gyj@OCM> select * from e;

EMPLOYEE_ID FIRST_NAME          MANAGER_ID

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

198 Donald                      124

199 Douglas                     124

省略结果。。。。。

gyj@OCM> select * from m;

EMPLOYEE_ID FIRST_NAME          MANAGER_ID

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

198 Donald                      124

199 Douglas                     124

省略结果。。。。。

数据字典中manager_id列的约束被删除了。所以答案B对

gyj@OCM> select CONSTRAINT_NAME from user_constraints wheretable_name='EMP';

no rows selected

去查视图,报错如下:

gyj@OCM> select * from v_emp;

select * from v_emp

*

ERROR at line 1:

ORA-04063: view "GYJ.V_EMP" has errors

此时视图不能用了。。。答案C的意思必须删除这个视图再重建这个视图才行,一定要这做吗?我不重建视图,在视图所在表中重新添加manager_id这一列,看看视图能不能用:

gyj@OCM> alter table emp add( MANAGER_ID NUMBER(6));

Table altered.

gyj@OCM> select * from v_emp;

EMPLOYEE_ID FIRST_NAME          MANAGER_ID

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

198 Donald

199 Douglas

省略结果。。。

说明视图无须删除和重建,只在表中添加刚刚被unused的这列就可以了,所以答案C错的

数据字典中manager_id列的索引被删除了。所以答案D错

gyj@OCM>  select index_name fromuser_indexes where table_name='EMP';

no rows selected

正确答案是:B

[每日一题] OCP1z0-047 :2013-07-26 alter table set unused之后各种情况处理的更多相关文章

  1. [Buzz.Today]2013.07.26

    # OpenFab 3D printing hardware is rapidly scaling up to output continuous mixtures of multiple mater ...

  2. 老男孩IT教育-每日一题汇总

    老男孩IT教育-每日一题汇总 第几天 第几周 日期 快速访问链接 第123天 第二十五周 2017年8月25日 出现Swap file….already exists以下错误如何解决? 第122天 2 ...

  3. PL/SQL Challenge 每日一题:2014-3-14 11gR2中带RELIES_ON子句的RESULT_CACHE函数

    PL/SQL Challenge 每日一题:2014-3-14 11gR2中带RELIES_ON子句的RESULT_CACHE函数 最先答对且答案未经编辑的puber将获得纪念章一枚(答案不可编辑但可 ...

  4. 【JavaScript】【dp】Leetcode每日一题-解码方法

    [JavaScript]Leetcode每日一题-解码方法 [题目描述] 一条包含字母 A-Z 的消息通过以下映射进行了 编码 : 'A' -> 1 'B' -> 2 ... 'Z' -& ...

  5. 【python】Leetcode每日一题-前缀树(Trie)

    [python]Leetcode每日一题-前缀树(Trie) [题目描述] Trie(发音类似 "try")或者说 前缀树 是一种树形数据结构,用于高效地存储和检索字符串数据集中的 ...

  6. LeetCode 每日一题「判定字符是否唯一」

    我是陈皮,一个在互联网 Coding 的 ITer,微信搜索「陈皮的JavaLib」第一时间阅读最新文章,回复[资料],即可获得我精心整理的技术资料,电子书籍,一线大厂面试资料和优秀简历模板. 题目 ...

  7. 【Java每日一题】20170106

    20170105问题解析请点击今日问题下方的"[Java每日一题]20170106"查看(问题解析在公众号首发,公众号ID:weknow619) package Jan2017; ...

  8. 【Java每日一题】20170105

    20170104问题解析请点击今日问题下方的"[Java每日一题]20170105"查看(问题解析在公众号首发,公众号ID:weknow619) package Jan2017; ...

  9. 【Java每日一题】20170104

    20170103问题解析请点击今日问题下方的"[Java每日一题]20170104"查看(问题解析在公众号首发,公众号ID:weknow619) package Jan2017; ...

随机推荐

  1. Android 平台 HTTP网速測试 案例 API 分析

    作者 : 万境绝尘 转载请注明出处 : http://blog.csdn.net/shulianghan/article/details/25996817 工信部规定的网速測试标准 : 除普通网页測速 ...

  2. sql server 视图 的一个例子

    这是一个 有点复杂的查询.我现在 想把他封装 成 视图  其中  B.RecordID= 41 提供给 视图外查询. create view view_UserRecord as select Rec ...

  3. linux open

    一直记住不打开文件时候的mode,今天发现原来可以直接用0644这样的八进制数字代替,好开森 #include <stdio.h> #include <sys/types.h> ...

  4. Java 之关键字 null 使用总结

    1.null的使用 Java中,null是一个关键字,用来标识一个不确定的对象.因此可以将null赋给引用类型变量,但不可以将null赋给基本类型变量.比如我们在定义一个变量的时候我们通过会这样做:X ...

  5. Java 类的成员初始化顺序

    做个简单笔录,就当是重温下基础知识. 1.先看代码: package com.test; public class Test { public static void main(String[] ar ...

  6. OCP-1Z0-051-题目解析-第10题

    10. View the Exhibit and examine the structure of the PROMOTIONS table. Each promotion has a duratio ...

  7. Goldeneye.py网站压力测试工具2.1版源码

    Goldeneye压力测试工具的源代码,粗略看了下,代码写的蛮规范和易读的,打算边读边加上了中文注释,但是想来也没太大必要,代码600多行,值得学习的地方还是蛮多的,喜欢Python的同学可以一读 这 ...

  8. leetcode第38题--Combination Sum

    题目: Given a set of candidate numbers (C) and a target number (T), find all unique combinations in C  ...

  9. C语言中的内存管理

    开始陆续的发一下唐老师视频的笔记吧,顺便带一些正冲哥书的的内容.不能一下都发出来,因为内容发多了自己也受不了,而且发的都是学习视频时候的一些笔记,可能会有一些问题不是很清晰. 先说一下C语言中的内存管 ...

  10. DataUml Design 课程6-DataUML Design 1.1版本号正式宣布(支持PD数据模型)

    从DataUML Design正式宣布到现在两个月,因为最近忙,出版到现在为止1.1版本号.稍后我们将始终坚持以良好DataUML Design软件,我希望程序员有很多支持. 一.1.1新的和改进的版 ...