Unique約束,Primary Key約束與索引的關係學習與測試_20091213.doc
Unique約束,Primary Key約束與索引的關係
<
<
1 Creating an Index Associated with a Constraint
Oracle enforces a UNIQUE key or PRIMARY KEY integrity constraint on a table by creating a unique index on the unique key or primary key. This index is automatically created by Oracle when the constraint is enabled. No action is required by you when you issue the CREATE TABLE or ALTER TABLE statement to create the index, but you can optionally specify a USING INDEX clause to exercise control over its creation. This includes both when a constraint is defined and enabled, and when a defined but disabled constraint is enabled. (唯一性約束和主鍵約束是透過建立唯一性索引來實現的,Oracle會自動建立,不必施加任何動作,但也可以透過USING INDEX clause 來施加控制,如改變Index Storage Clause)
A constraint’s associated index always assumes the name of the constraint, unless you optionally specify otherwise.
2 Specifying Storage Options for an Index Associated with a Constraint
CREATE TABLE emp (
empno NUMBER(5) PRIMARY KEY, age INTEGER)
ENABLE PRIMARY KEY USING INDEX
TABLESPACE users
PCTFREE 0;
Enable Constraints 的時候指定相應索引的儲存引數
3 Specifying the Index Associated with a Constraint
Create table a (a1 int primary key using index( create index ai on a(a1)));
idle> Create table a (a1 int primary key using index( create index ai on t2(name)));
Create table a (a1 int primary key using index( create index ai on t2(name)))
*
ERROR at line 1:
ORA-00600: internal error code, arguments: [kkdccui3], [], [], [], [], [], [], []
必須是自身表,而不能使用別的表
CREATE TABLE b(
b1 INT,
b2 INT,
CONSTRAINT bu1 UNIQUE (b1, b2)
USING INDEX (create unique index bi on b(b1, b2)),
CONSTRAINT bu2 UNIQUE (b2, b1) USING INDEX bi);
CREATE TABLE c(c1 INT, c2 INT);
CREATE INDEX ci ON c (c1, c2);
ALTER TABLE c ADD CONSTRAINT cpk PRIMARY KEY (c1) USING INDEX ci;
4 刪除index 的情況
顯示建立的索引,顯示刪除,隱式建立的索引不能顯式刪除,只能透過禁止或者刪掉約束來達到刪除索引的目的.
idle> create table t2 (id number primary key, name varchar2(20));
Table created.
idle> select object_type, object_name from user_objects order by object_type;
OBJECT_TYPE
------------------
OBJECT_NAME
--------------------------------
SYS_C002101
TABLE
T1
TABLE
T2
idle> drop index SYS_C002101;
drop index SYS_C002101
*
ERROR at line 1:
ORA-02429: cannot drop index used for enforcement of unique/primary key
不能顯式刪除
idle> alter table t2 disable constraint SYS_C002101;
Table altered.
禁止約束
idle> select object_type, object_name from user_objects order by object_type;
OBJECT_TYPE OBJECT_NAME
------------------ --------------------
TABLE T1
TABLE T2
索引被刪除
If a table is dropped, all associated indexes are dropped automatically.(索引依賴於表)
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/10248702/viewspace-622324/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 【SQL】15 SQL 約束(Constraints)、NOT NULL 約束、UNIQUE 約束、PRIMARY KEY 約束、FOREIGN KEY 約束、CHECK 約束、DEFAULT約束SQLAINull
- Oracle約束的學習與測試Oracle
- MySQL中的 UNIQUE約束和UNIQUE索引MySql索引
- NULL和唯一約束UNIQUE的對應關係Null
- MySQL學習筆記——建立與約束MySql筆記
- IDELAY約束測試IDE
- 《學習》6約束
- 很多人比較糾結的約束和索引的關係索引
- 【從零開始學習Oracle資料庫】(5)約束檢視與索引Oracle資料庫索引
- 【從零開始學習 MySql 資料庫】(5) 約束檢視與索引MySql資料庫索引
- SQL FOREIGN KEY 約束SQL
- set unused column和檢視,約束,同義詞和索引的關係索引
- Oracle主鍵約束、唯一鍵約束、唯一索引的區別(轉)Oracle索引
- unique index與primary key的區別Index
- Javaweb-約束-外來鍵約束JavaWeb
- oracle約束學習經典案例Oracle
- 差分約束學習筆記筆記
- Django模型之欄位與約束Django模型
- 深度學習中的Lipschitz約束:泛化與生成模型深度學習模型
- Oracle定義約束 外來鍵約束Oracle
- Oracle - 約束、索引等相關常用操作語句Oracle索引
- SQL約束SQL
- Oracle約束Oracle
- oracle 約束Oracle
- MySQL 約束MySql
- 03約束
- 綜合約束
- mysql中key 、primary key 、unique key 與index區別MySqlIndex
- (10)邏輯綜合新增約束(環境約束)
- 建約束(Constraint)時隱式建立索引(Index)及先建立索引後建立約束的區別AI索引Index
- 用函式索引構造特殊的約束函式索引
- Oracle如何管理帶約束的B樹索引Oracle索引
- TreeSet的null值與元素型別的約束Null型別
- 【PK】Oracle 10g刪除主鍵約束後無法刪除唯一約束索引問題的模擬與分析Oracle 10g索引
- oracle中的約束Oracle
- MySQL學習筆記之約束條件MySql筆記
- 約束介紹
- 差分約束