PK Nounique CASCADE DROP INDEX keep index

Explicit Control Over Indexes when Creating, Disabling, or Dropping PK/Unique Constraints (Doc ID 139666.1)​编辑To Bottom


PURPOSEIn Oracle 9i, the DBA has an explicit control over how indexes are affectedwhile creating, disabling, or dropping Primary Key (PK) and unique constraints.This bulletin explains the different behaviours of indexes associated withPrimary Key or UNIQUE constraints according to the new clauses used when you execute one of the following commands:CREATE TABLE ... PRIMARY KEY/UNIQUEALTER TABLE  ... DISABLE PRIMARY KEY/UNIQUEALTER TABLE  ... DROP PRIMARY KEY/UNIQUESCOPE & APPLICATIONIt is important for DBAs to know what happens to the indexes when creating,disabling or dropping a constraint relying on an index, since indexes may have to be rebuilt after these operations. This can have two consequences:- Indexes may be missing for the Cost Based Optimizer (CBO) if the DBA thinks that the index was not dropped. This can have a major impact on performance.- Index rebuilding takes time.Explicit control over INDEXES when DISABLING/DROPPING PK, Unique constraints:
=============================================================================A. Creation of Primary Key/Unique constraints and associated index ----------------------------------------------------------------In the following views, depending on the way you created the Primary Key (PK)or UNIQUE constraint and its associated index, you get these different combinations:+-----------------+        +------------+| DBA_CONSTRAINTS |        | DBA_INDEXES|+-----------------+        +------------+-----------------------------   ------------Constraint_name   Index_name     Index_name--------------- -------------   ------------
Case 1: Create constraint, and index   PK_EMP_ID     EMP_ID_IX      EMP_ID_IX    explicitely within the samestatement.Case 2: Create constraint, and index   PK_EMP_ID     PK_EMP_ID      PK_EMP_ID    implicitely within the same statement.Case 3: Create constraint and index    PK_EMP_ID         -          EMP_ID_IX   separately within twostatements.Enable the constraint.         PK_EMP_ID     EMP_ID_IX      EMP_ID_IX-------------------------------------------------------------------------
Case 1: Create constraint and index explicitely within the same statement
-------------------------------------------------------------------------SQL> drop table <OWNER>.<TABLE_NAME>
Table dropped.SQL> create table <OWNER>.<TABLE_NAME>(emp_id NUMBERCONSTRAINT pk_emp_id PRIMARY KEY USING INDEX(CREATE INDEX <OWNER>.emp_id_ix ON <OWNER>.<TABLE_NAME>(emp_id)TABLESPACE indx),ename VARCHAR2(12),sal   number);Table created.SQL> select index_name,uniqueness from dba_indexes where table_name='<TABLE_NAME>';INDEX_NAME                     UNIQUENES------------------------------ ---------EMP_ID_IX                      NONUNIQUESQL> select constraint_name,index_name, constraint_type from dba_constraintswhere table_name='<TABLE_NAME>' and constraint_type='P';CONSTRAINT_NAME                INDEX_NAME                     C------------------------------ ------------------------------ -PK_EMP_ID                      EMP_ID_IX                      P-------------------------------------------------------------------------
Case 2: Create constraint and index implicitely within the same statement
-------------------------------------------------------------------------SQL> drop table <OWNER>.<TABLE_NAME>
Table dropped.SQL> create table <OWNER>.<TABLE_NAME>(emp_id NUMBERCONSTRAINT pk_emp_id PRIMARY KEY USING INDEX TABLESPACE indx,ename VARCHAR2(12),sal   number);Table created.SQL> select index_name,uniqueness from dba_indexes where table_name='<TABLE_NAME>';INDEX_NAME                     UNIQUENES------------------------------ ---------PK_EMP_ID                      UNIQUESQL> select constraint_name,index_name, constraint_type from dba_constraintswhere table_name='<TABLE_NAME>' and constraint_type='P';CONSTRAINT_NAME                INDEX_NAME                     C------------------------------ ------------------------------ -PK_EMP_ID                      PK_EMP_ID                      P--------------------------------------------------------------------
Case 3: Create constraint and index separately within two statements
--------------------------------------------------------------------SQL> drop table <OWNER>.<TABLE_NAME>
Table dropped.SQL> create table <OWNER>.<TABLE_NAME>(emp_id NUMBERCONSTRAINT pk_emp_id PRIMARY KEY  DISABLE,ename VARCHAR2(12),sal   number);Table created.SQL> create index <OWNER>.emp_id_ix on <OWNER>.<TABLE_NAME>(emp_id)tablespace indx;
Index created.SQL> select index_name,uniqueness from dba_indexes where table_name='<TABLE_NAME>';INDEX_NAME                     UNIQUENES------------------------------ ---------EMP_ID_IX                      NONUNIQUESQL> select constraint_name,index_name, constraint_type from dba_constraintswhere table_name='<TABLE_NAME>' and constraint_type='P';CONSTRAINT_NAME                INDEX_NAME                     C------------------------------ ------------------------------ -PK_EMP_ID                                                     PSQL> alter table <OWNER>.<TABLE_NAME> ENABLE constraint pk_emp_id;
Table altered.SQL> select index_name,uniqueness from dba_indexes where table_name='<TABLE_NAME>';INDEX_NAME                     UNIQUENES------------------------------ ---------EMP_ID_IX                      NONUNIQUESQL> select constraint_name,index_name, constraint_type from dba_constraintswhere table_name='<TABLE_NAME>' and constraint_type='P';CONSTRAINT_NAME                INDEX_NAME                     C------------------------------ ------------------------------ -PK_EMP_ID                      EMP_ID_IX                      PB. Disabling PK/UNIQUE constraints: what happens to the associated index ---------------------------------------------------------------------In Case 1 where the index was created explicitely within the same statementas the constraint, the index is in both cases disassociated from the constraint; depending on the clause "CASCADE DROP INDEX" usage, the index is dropped or not.In traditionnal Case 2, the behavior remains the same: using the clause "CASCADE DROP INDEX" or not does not influence the usual behavior: it automatically drops the relying index.In case 3, disabling the constraint drops the index or not: * if the constraint has never been enabled, it never drops the index.* but in most cases, the constraint has been enabled for some time. In this case, the clause "CASCADE DROP INDEX" drops the index.+-----------------+       +------------+| DBA_CONSTRAINTS |       | DBA_INDEXES|+-----------------+       +------------+-----------------------------   ------------Constraint_name   Index_name     Index_name--------------- -------------   ------------
Case 1: ALTER TABLE ... DISABLE PK     PK_EMP_ID         -             -        CASCADE DROP INDEX;orALTER TABLE ... DISABLE PK;    PK_EMP_ID         -         EMP_ID_IX    Case 2: ALTER TABLE ... DISABLE PK     PK_EMP_ID         -             -       CASCADE DROP INDEX;or ALTER TABLE ... DISABLE PK;    PK_EMP_ID         -             -      Case 3: ALTER TABLE ... DISABLE PK     PK_EMP_ID         -             -    CASCADE DROP INDEX;or ALTER TABLE ... DISABLE PK;    PK_EMP_ID         -         EMP_ID_IXC. Dropping PK/UNIQUE constraints: what happens to the associated index ---------------------------------------------------------------------In Case 1, where the index was created explicitely within the same statementas the constraint, the index is by default KEPT when the constraint is dropped.If you want the index to be dropped, you have to explicitely ask for it through the "DROP INDEX" clause.In case 2, the behavior is the opposite: if you want the index to be kept and the constraint dropped, you have to explicitly ask for it with the "KEEP INDEX" clause; otherwise the index is DROPPED by default.In Case 3, dropping the constraint drops the index or not: * if the constraint has never been enabled, it never drops the index.* but in most cases, the constraint has been enabled for some time. Then the index is by default KEPT when the constraint is dropped. If you want the index to be dropped, you have to explicitly ask for it with the "DROP INDEX" clause.+-----------------+   +-----------+| DBA_CONSTRAINTS |   |DBA_INDEXES|+-----------------+   +-----------+----------------------- ------------Constraint  Index_name   Index_name----------- ----------- ------------
Case 1: ALTER TABLE ... DROP PK DROP INDEX;     -            -           -       
Case 1: ALTER TABLE ... DROP PK KEEP INDEX;     -            -       EMP_ID_IX              
Case 1: ALTER TABLE ... DROP PK;                -            -       EMP_ID_IX   Case 2: ALTER TABLE ... DROP PK DROP INDEX;     -            -           -                                                      
Case 2: ALTER TABLE ... DROP PK KEEP INDEX;     -            -       PK_EMP_ID                                                              
Case 2: ALTER TABLE ... DROP PK;                -            -           -       Case 3: ALTER TABLE ... DROP PK DROP INDEX;     -            -           -   
Case 3: ALTER TABLE ... DROP PK KEEP INDEX;     -            -       EMP_ID_IX   
Case 3: ALTER TABLE ... DROP PK;                -            -       EMP_ID_IX

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/32687.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

AI Deep Reinforcement Learning Autonomous Driving(深度强化学习自动驾驶)

AI Deep Reinforcement Learning Autonomous Driving&#xff08;深度强化学习自动驾驶&#xff09; 背景介绍研究背景研究目的及意义项目设计内容算法介绍马尔可夫链及马尔可夫决策过程强化学习神经网络 仿真平台OpenAI gymTorcs配置GTA5 参数选择行动空间奖励函数 环境及软件…

【雕爷学编程】Arduino动手做(13)---TTP223B电容式触摸模块之通过串口监视器检测电容触摸键的状态与控制继电器

37款传感器与模块的提法&#xff0c;在网络上广泛流传&#xff0c;其实Arduino能够兼容的传感器模块肯定是不止37种的。鉴于本人手头积累了一些传感器和执行器模块&#xff0c;依照实践出真知&#xff08;一定要动手做&#xff09;的理念&#xff0c;以学习和交流为目的&#x…

C语言学习笔记 使用vscode外部console出现闪退-12

前言 在使用vscode的外部console时&#xff0c;会出现闪退现象&#xff0c;这是因为程序运行结束后&#xff0c;系统自动退出了终端&#xff08;终端机制决定的&#xff09;。我们可以在C程序结束后&#xff0c;使用system函数来暂停DOS终端系统&#xff0c;这样就可以完整地看…

SAP Fiori 问题收集

事务代码篇 启动工作台&#xff1a;/N/UI2/FLP 错误日志&#xff1a; /n/IWFND/ERROR_LOG 服务清单&#xff1a; /n/IWFND/MAINT_SERVICE 创建语义对象&#xff1a;/N/UI2/SEMOBJ 创建目录&#xff1a;/N/UI2/FLPD_CONF&#xff08;cross-client&#xff09;或 /N/UI2…

爬虫018_urllib库_cookie反爬_post请求百度翻译获取百分翻译内容_以及详细翻译内容---python工作笔记037

然后我们来看如何用urllib发送post请求,这里我们 用百度翻译为例 我们翻译一个spider,然后我们看请求,可以看到有很多 找到sug这个 可以看到这里的form data,就是post请求体中的内容 然后我们点击preview其实就是 返回的实际内容 然后请求方式用的post 然后我们把上面的信息…

maven是什么?安装+配置

目录 1.什么是maven&#xff1f; 1.2.maven的核心功能是什么&#xff1f; 2.Maven安装配置 2.1Maven的安装 2.2Maven环境配置 1.配置 MAVEN_HOME &#xff0c;变量值就是你的 maven 安装的路径&#xff08;bin 目录之前一级目录&#xff09; 2.将MAVEN_HOME 添加到Path系…

Groovy语法

工程目录 请点击下面工程名称&#xff0c;跳转到代码的仓库页面&#xff0c;将工程 下载下来 Demo Code 里有详细的注释 代码&#xff1a;LearnGroovy 参考文献 配置Groovy开发环境(Windows)IntelliJ IDEA创建第一个Groovy工程基于IntelliJ IDEA创建第一个Groovy工程

Ubuntu18.04版本安装ROS及出现错误的处理方法

前面的文章是在已安装的ROS基础上做的一些应用&#xff0c;这里我们从零开始安装ROS机器人操作系统。 机器人操作系统(Robot Operating System,ROS)是一个开发机器人软件的框架&#xff0c;里面包含了一系列的工具&#xff0c;库和惯例&#xff0c;目的在于简化在大量不同种类机…

Flink正常消费一段时间后,大量反压,看着像卡住了,但又没有报错。

文章目录 前言一、原因分析二、解决方案 前言 前面我也有提到&#xff0c;发现flink运行一段时间后&#xff0c;不再继续消费的问题。这个问题困扰了我非常久&#xff0c;一开始也很迷茫。又因为比较忙&#xff0c;所以一直没有时间能够去寻找答案&#xff0c;只是通过每天重启…

函数的模拟实现

题一&#xff1a; 模拟实现strncpy #include <stdio.h>void my_strncpy(char* arr2, char* arr1, size_t num){int i 0;for (i 0; i < num; i){*(arr2 i) *(arr1 i);}}int main(){char arr1[] "hello liangzai";char arr2[10] { 0 };//strncpy(ar…

安装elasticsearch

一、docker安装elasticsearch 1、下载镜像 docker pull elasticsearch:6.5.4 2、启动容器 docker run -p 9200:9200 -p 9300:9300 --name elasticsearch \ -e "discovery.typesingle-node" \ -e "cluster.nameelasticsearch" \ -e "ES_JAVA_OPTS-Xm…

MySQL——Mysql安装教程- Windows

一、Mysql安装 1、下载mysql安装包 下载链接&#xff1a; 链接&#xff1a; https://pan.baidu.com/s/1rFpMqOCApiQQEwYSs9XSmg https://pan.baidu.com/s/1rFpMqOCApiQQEwYSs9XSmg 提取码&#xff1a;zt88 2、 安装 1&#xff09;选择电脑磁盘空闲的路径&#xff1a; 2&…

Small Tip: 如何Debug Start Routine

我也不知道咋地&#xff0c;在generated ABAP里面打断点进不去。 我也不晓得怎么弄&#xff0c;今天反正是硬找着去弄。不晓得有没有其他好办法。有知道的小伙伴评论下吧。 1、 在DTP里面选Before Transformation&#xff0c;要去debug start routine选这个就够了。其他的随意…

吉利科技携手企企通,打造集团化数智供应链系统

近日&#xff0c;吉利科技集团有限公司&#xff08;以下简称“吉利科技”&#xff09;联合企企通成功召开SRM采购供应链管理项目启动会。企企通与吉利科技高层、项目负责人与团队成员出席此次启动会。 双方将携手在企业供应商全生命周期管理、采购全流程、电子招投标、采购分析…

Python基础小项目

今天给大家写一期特别基础的Python小项目&#xff0c;欢迎大家支持&#xff0c;并给出自己的完善修改 &#xff08;因为我写的都是很基础的&#xff0c;运行速率不是很好的 目录 1. 地铁票价题目程序源码运行截图 2. 购物车题目程序源码运行截图 3. 名片管理器题目程序源码运行…

Maven依赖管理

依赖配置 依赖指的是项目在运行时所需要的jar包&#xff0c;一个项目中可以引入多个依赖 配置方法 1.在项目pom.xml中编写 <dependencies> 标签 2.在 <dependencies> 标签中使用<dependency>引入坐标 3.定义坐标的groupId,artifactId,version 4. 刷新按钮&a…

接口测试—Fiddler工具

文章目录 Fiddler 知识1. 导语2. 配置3. 常用命令面试题1. 利用Fiddler抓取android设备https请求 Fiddler 知识 未完待续 1. 导语 为什么要用Fiddler&#xff1f; 提高测试效率. 测试人员通过使用Fiddler自己调试接口&#xff0c;无需麻烦后台同学帮忙. 模拟多种测试环境. 可…

棒球课堂的发展规划·棒球联盟

棒球课堂的发展规划 1. 棒球课堂的发展环境 探讨棒球课堂如何通过运用创新的教学方法来适应不断变化的市场需求。包括但不限于&#xff0c;科学地运用大数据和人工智能技术来提高教学效率&#xff0c;加强教师队伍的专业培训&#xff0c;以及拓展课外活动&#xff0c;增强学生…

【果树农药喷洒机器人】Part3:变量喷药系统工作原理介绍

本专栏介绍&#xff1a;免费专栏&#xff0c;持续更新机器人实战项目&#xff0c;欢迎各位订阅关注。 关注我&#xff0c;带你了解更多关于机器人、嵌入式、人工智能等方面的优质文章&#xff01; 文章目录 一、变量喷药系统工作原理二、液压通路设计与控制系统封装2.1液压通路…

企业权限管理(八)-登陆使用数据库认证

Spring Security 使用数据库认证 在 Spring Security 中如果想要使用数据进行认证操作&#xff0c;有很多种操作方式&#xff0c;这里我们介绍使用 UserDetails 、 UserDetailsService来完成操作。 UserDetails public interface UserDetails extends Serializable { Collecti…