正确答案:B

一、USING INDEX的实验:

1、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_PKgyj@MYDB> select UNIQUENESS from user_indexes where index_name='EMP_ID_PK';UNIQUENES
---------
UNIQUE

2、这时我想把主键删除,但我想保留唯一索引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
---------
UNIQUEgyj@MYDB>  select INDEX_NAME from user_constraints where CONSTRAINT_NAME='EMP_ID_PK';no rows selected

3、然后我又想创建主键,但我想直接用刚刚创建的唯一索引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. acwing每日一题(8.12 ~ 8.14)

    2022.8.12 Leetcode 128  用户分组 1282. 用户分组 - 力扣(LeetCode) 思路:我们用哈希表存储  键:不同大小的组     值:组内元素 (用一个链表或者Arra ...

  2. 【每日一题】 面试题 17.14. 最小K个数

    面试题 17.14. 最小K个数

  3. pmp每日三题(2022年3月14日)

    今日三题答案-BAA 1.由于项目执行期间的范围变更,项目经理确定供应商必须对一个已在使用的产品模块进行更改.项目经理首先做什么? A. 准备一份变更请求,以更新供应商的合同条款 B. 检查采购管理计 ...

  4. PMP每日三题(2022年2月14日)

    今日三题答案-DDD 1.对于一个长期的基础设施项目,由于全球商业环境,项目经理必须获得风险最小的供应商.项目经理应该使用什么合同类型? A.固定总价合同(FFP) B.成本加固定费用合同(CPFF) ...

  5. Leetcode每日一题:面试题 08.02. 迷路的机器人

    思路:深度优先搜索:设立一个全局变量flag,一旦找到终点,便将flag置为true,防止其进一步寻求多条路径: 加visited时,很多人选择new一个二维数组出来,然而这里我们只需将已被试过无法到 ...

  6. (每日一题)P4841 [集训队作业2013]城市规划 (无向连通图计数)(普通生成函数 + 多项式求逆)

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 每日一题(莫反 / 多项式 / 母函数 / 群论) 2021.4.14 生成函数 + 多项式求逆 Pr ...

  7. 电动力学每日一题 2021/10/14

    电动力学每日一题 2021/10/14 (a) Define r∣∣=xx^+yy^\textbf r_{||}=x\hat x+y\hat yr∣∣​=xx^+yy^​, r∣∣=x2+y2r_{| ...

  8. leetcode每日一题--前缀树;前缀哈希;深搜;面试题 08.04. 幂集;648. 单词替换面试题 01.09. 字符串轮转;剑指 Offer II 062. 实现前缀树

    leetcode每日一题 ps:今天的每日一题没意思,简单的模拟,自己换一道 面试题 08.04. 幂集 幂集.编写一种方法,返回某集合的所有子集.集合中不包含重复的元素. 说明:解集不能包含重复的子 ...

  9. 面试—每日一题(8)

    好长时间没有更新博客了,特别是这个专栏,一是因为自己比较忙,二是因为我还是比较懒的缘故.让各位见笑了.今天在更新一篇. 像什么strcpy.strcat等等字符串的操作和实现在面试中经常出现,不管是上 ...

最新文章

  1. linux更换网卡不识别_详解Linux双网卡绑定脚本的方法示例
  2. LeetCode 417. 太平洋大西洋水流问题(BFS/DFS)
  3. 50T内存?百万机时?头一次见这么耗费内存和机时的分析?
  4. [Elasticsearch] es 6.6 编译报错 java.net.ConnectException: Operation timed out
  5. 国家计算机房机柜接地图集,中国铁塔机房及室外机柜标准图集.pdf
  6. android 手机地图
  7. 线性分类器三种最优准则
  8. 基于SSM的高校学生宿舍报修管理系统
  9. cascader 动态加载 回显_elementUI的cascader级联选择控件的默认值(回显)问题
  10. 银行活期存取款业务处理系统的数据流图
  11. WML语言基础(WAP建站)一
  12. License Check
  13. 全产业链模式的竞争优势
  14. 为什么连麦对面能听到我电脑内部的声音
  15. Crontab 每两周执行一次
  16. 如何在html中添加分享按钮
  17. eeglab脑电头皮地形图原理学习
  18. ios设备使用socks代理
  19. Windows清理助手最新版3.1发布及下载地址
  20. PTN设备中为什么不支持PHP,ptn和otn的区别是什么

热门文章

  1. 【玩转.Net MF – 03】远程文件查看器
  2. 亚洲诚信带你玩转[2018国家网络安全宣传周]上海地区活动!
  3. Hadoop版本:CDH, HDP, MapR
  4. GIS软件开发工具包TatukGIS Developer Kernel 发布 v11.3.0-Unstable1丨附下载
  5. jQuer or js 插件aptana studio 3.4.0)教你玩转eclipse配置(全世
  6. 删除条目时的确认对话框
  7. 解决putty中文乱码并远程访问linux界面功能
  8. 360safe:腾讯QQ也见不得人[图]
  9. Jquery之dom操作
  10. 如何优雅地实现分页查询