在Oracle中,可以在创建主键约束的时候自动创建唯一索引,也可以先创建唯一索引,然后再基于这个唯一索引来创建主键约束。后一种
在Oracle中,可以在创建主键约束的时候自动创建唯一索引,也可以先创建唯一索引,然后再基于这个唯一索引来创建主键约束。后一种方式有一个好处,在 需要对数据量比较大而且读写频繁的OLTP表创建主键约束的时候,可以先ONLINE的创建一个唯一的索引,然后再创建主键约束,这样可以减少对表的读写 阻塞。但这样就带来一个问题,第一种方式创建的索引在删除约束的时候索引会被自动删除,而第二种方式创建的索引在删除约束的时候不会自动删除,,需要删完约 束删索引,如果忘记了这个唯一索引的话,可能会带来跟想象不一样的结果。同时,Oracle针对这种情况提供了特殊的删除约束的方法,可以同时删除约束和 索引,就是:alter table bear drop constraint pk_bear drop index。在删除约束的最后加上删除索引的关键字。
但写这一大堆都不是这里要重点描述的内容,这里要写的是怎么知道已经创建好的索引到底是第一种方式创建的?还是第二种方式创建的呢?
在Oracle的SYS.IND$视图中有一个叫PROPERTY的字段,里面记录的就是每个索引对应的属性,这个字段的含义是在创建这个表的SQL中有定义的。在10G的版本中,可以到$Oracle_HOME/rdbms/admin/sql.bsp中查找ind$表的创建脚本;在11G的版本中,可以到相同的位置的dcore.bsp中查找。这些脚本都是创建系统核心表的脚本,很多字段在官方文档中没有注释的,可以来这里找找看。在11G中对PROPERTY字段的注释如下:
property number not null, /* immutable flags for life of the index */
/* unique : 0x01 */
/* partitioned : 0x02 */
/* reverse : 0x04 */
/* compressed : 0x08 */
/* functional : 0x10 */
/* temporary table index: 0x20 */
/* session-specific temporary table index: 0x40 */
/* index on embedded adt: 0x80 */
/* user said to check max length at runtime: 0x0100 */
/* domain index on IOT: 0x0200 */
/* join index : 0x0400 */
/* system managed domain index : 0x0800 */
/* The index was created by a constraint : 0x1000 */
/* The index was created by create MV : 0x2000 */
/* composite domain index : 0x8000 */
这个是典型的Oracle的表示方法,其中每个值表示一个含义,但是多个值是可以累加起来表示多个含义的。比如一个UNIQUE的REVERSE的索引,对应的值就会是0X05,PROPERTY中对应的是10进制的存放,就应该也是5。
可以用下面的SQL来查询主键跟索引的关系是第一种还是第二种:
SELECT DECODE(BITAND(PROPERTY, 4096), 4096, 'implicit', 'user-generated') GENERATION,
B.INDEX_NAME
FROM SYS.IND$ A, USER_INDEXES B, USER_OBJECTS C
WHERE B.UNIQUENESS = 'UNIQUE'
AND A.OBJ# = C.OBJECT_ID
AND B.INDEX_NAME = C.OBJECT_NAME
AND B.INDEX_NAME = 'INDEX_NAME';
上面的SQL就是说如果PROPERTY为4096,那么对应到16进制应该是0X1000,也就表示The index was created by a constraint,也就是第一种;其他都是第二种,这种情况下典型的值就是4097,也就是0X1000和0X01值的和。

This article explores optimizing MySQL memory usage in Docker. It discusses monitoring techniques (Docker stats, Performance Schema, external tools) and configuration strategies. These include Docker memory limits, swapping, and cgroups, alongside

This article addresses MySQL's "unable to open shared library" error. The issue stems from MySQL's inability to locate necessary shared libraries (.so/.dll files). Solutions involve verifying library installation via the system's package m

The article discusses using MySQL's ALTER TABLE statement to modify tables, including adding/dropping columns, renaming tables/columns, and changing column data types.

This article compares installing MySQL on Linux directly versus using Podman containers, with/without phpMyAdmin. It details installation steps for each method, emphasizing Podman's advantages in isolation, portability, and reproducibility, but also

This article provides a comprehensive overview of SQLite, a self-contained, serverless relational database. It details SQLite's advantages (simplicity, portability, ease of use) and disadvantages (concurrency limitations, scalability challenges). C

This guide demonstrates installing and managing multiple MySQL versions on macOS using Homebrew. It emphasizes using Homebrew to isolate installations, preventing conflicts. The article details installation, starting/stopping services, and best pra

Article discusses configuring SSL/TLS encryption for MySQL, including certificate generation and verification. Main issue is using self-signed certificates' security implications.[Character count: 159]

Article discusses popular MySQL GUI tools like MySQL Workbench and phpMyAdmin, comparing their features and suitability for beginners and advanced users.[159 characters]


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 English version
Recommended: Win version, supports code prompts!

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)
