正确答案:B

一、USING INDEX的实验:

、USING INDEX可以让你在创建主键、唯一性约束的时候使用指定的索引或创建索引、或修改索引的存储结构。

OK,我先不用USING INDEX,创建主键时Oracle自动创建唯一索引。

gyj@MYDB> alter table emp add constraint emp_id_pk primary key(employee_id);

Table altered.

gyj@MYDB> select INDEX_NAME from user_constraints where CONSTRAINT_NAME='EMP_ID_PK';

INDEX_NAME
------------------------------
EMP_ID_PK gyj@MYDB> select UNIQUENESS from user_indexes where index_name='EMP_ID_PK'; UNIQUENES
---------
UNIQUE

、这时我想把主键删除,但我想保留唯一索引EMP_ID_PK,即约束可以被独立drop,而索引可以保留。

gyj@MYDB> ALTER TABLE emp DROP PRIMARY KEY KEEP INDEX;

Table altered.

gyj@MYDB> select UNIQUENESS from user_indexes where index_name='EMP_ID_PK';

UNIQUENES
---------
UNIQUE gyj@MYDB> select INDEX_NAME from user_constraints where CONSTRAINT_NAME='EMP_ID_PK'; no rows selected

、然后我又想创建主键,但我想直接用刚刚创建的唯一索引EMP_ID_PK。此时我就要用USING INDEX。

gyj@MYDB> alter table emp add constraint emp_id_pk primary key(employee_id) using index EMP_ID_PK;

Table altered.

二、      USING INDEX在官方文的解释:

Using Indexes to Enforce Constraints

When defining the state of a unique or primary key constraint, you can specify an index for Oracle to use to enforce the constraint, or you can instruct Oracle to create the index used to enforce the constraint.

using_index_clauseYou can specify the using_index_clause only when enabling unique or primary key constraints. You can specify the clauses of theusing_index_clause in any order, but you can specify each clause only once.

  • If you specify schema.index, then Oracle attempts to enforce the constraint using the specified index. If Oracle cannot find the index or cannot use the index to enforce the constraint, then Oracle returns an error.

  • If you specify the create_index_statement, then Oracle attempts to create the index and use it to enforce the constraint. If Oracle cannot create the index or cannot use the index to enforce the constraint, then Oracle returns an error.

  • If you neither specify an existing index nor create a new index, then Oracle creates the index. In this case:

    • The index receives the same name as the constraint.

    • If table is partitioned, then you can specify a locally or globally partitioned index for the unique or primary key constraint.

Restrictions on theusing_index_clause The following restrictions apply to theusing_index_clause:

  • You cannot specify this clause for a view constraint.

  • You cannot specify this clause for a NOT NULL, foreign key, or check constraint.

  • You cannot specify an index (schema.index) or create an index (create_index_statement) when enabling the primary key of an index-organized table.

  • You cannot specify the domain_index_clause of index_properties or theparallel_clause of index_attributes.

[每日一题] OCP1z0-047 :2013-08-14 如何理解USING INDEX?...................................41的更多相关文章

  1. Cheatsheet: 2013 08.14 ~ 08.19

    .NET Lucene.Net ultra fast search for MVC or WebForms site => made easy! C# State Machines HttpCl ...

  2. CISP/CISA 每日一题 14

    CISA 每日一题(答) 自动无人值守运行(LIGHTS-OUT)优势:1.信息系统运行成本的遏制/减少:2.持续运行(24/7):3.减少系统错误和中断次数. I/O 控制人员负责保证:1.批处理信 ...

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

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

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

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

  5. CISP/CISA 每日一题 五

    CISA 每日一题(答) 信息系统审计师要确认系统变更程序中的: 1.变更需求应有授权.优先排序及跟踪机制: 2.日常工作手册中,明确指出紧急变更程序: 3.变更控制程序应同时为用户及项目开发组认可: ...

  6. [每日一题]面试官问:谈谈你对ES6的proxy的理解?

    [每日一题]面试官问:谈谈你对ES6的proxy的理解? 关注「松宝写代码」,精选好文,每日一题 作者:saucxs | songEagle 一.前言 2020.12.23 日刚立的 flag,每日一 ...

  7. 【JavaScript】Leetcode每日一题-在D天内送包裹的能力

    [JavaScript]Leetcode每日一题-在D天内送包裹的能力 [题目描述] 传送带上的包裹必须在 D 天内从一个港口运送到另一个港口. 传送带上的第 i 个包裹的重量为 weights[i] ...

  8. 【python】Leetcode每日一题-寻找旋转排序数组中的最小元素

    [python]Leetcode每日一题-寻找旋转排序数组中的最小元素 [题目描述] 已知一个长度为 n 的数组,预先按照升序排列,经由 1 到 n 次 旋转 后,得到输入数组.例如,原数组nums ...

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

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

随机推荐

  1. QWidget QMainWindow QDialog 三者区别

    Qt类是一个提供所需的像全局变量一样的大量不同的标识符的命名空间.通常情况下,你可以忽略这个类.QObject和一些其它类继承了它,所以在这个Qt命名空间中定义的所有标识符通常情况下都可以无限制的使用 ...

  2. window对象细节(转载)

    Window对象是客户端javascript最高层对象之一,只要打开浏览器窗口,不管该窗口中是否有打开的网页,当遇到BODY.FRAMESET或FRAME元素时,都会自动建立window对象的实例.另 ...

  3. js常用效果

    //创建元素 var txt1="<p style='color:red'>我是由HTML创建的</p>"; // 以 HTML 创建新元素 var txt ...

  4. LGDT/LIDT-加载全局/中断描述符表寄存器

    将源操作数中的值加载到全局描述符表寄存器 (GDTR) 或中断描述符表寄存器 (IDTR).源操作数指定 6 字节内存位置,它包含全局描述符表 (GDT) 或中断描述符表 (IDT) 的基址(线性地址 ...

  5. javascript常用代码大全

    http://caibaojian.com/288.html    原文链接 jquery选中radio //如果之前有选中的,则把选中radio取消掉 $("#tj_cat .pro_ca ...

  6. workerman需要的php模块posix、pcntl、sysvshm、sysvmsg缺少,怎么办

    如果您的php是源码编译,那么请进到php的源码目录,再进入ext目录下,分别找到相应的php模块目录,进行编译 1. 假设php目录为/usr/local/php, 进到相应的php模块目录,执行 ...

  7. truncate 命令删除恢复

    truncate命令可以一次性删除当前表中所有记录并且不留任何日志,同时这个表的ID就自动初化从1开始,今天我就来给大家尝试一个利用truncate清除记录之后恢复过程. 实际线上的场景比较复杂,当时 ...

  8. OC面向对象的三大特征

    OC面向对象的三大特征 1.OC面向对象的三大特封装 1)封装:完整的说是成员变量的封装. 2)在成语方法里面的成员变量最好不要使用@public这样会直接暴露在外面被别人随随便便修改,封装的方法还可 ...

  9. NYOJ 540

    为了给学弟学妹讲课,我水了一道题…… import java.util.Arrays; import java.util.Scanner; public class NYOJ540 { public ...

  10. JVM系列五:JVM监测&工具

    JVM系列五:JVM监测&工具[整理中]  http://www.cnblogs.com/redcreen/archive/2011/05/09/2040977.html 前几篇篇文章介绍了介 ...