Oracle 10g中unique與index的問題
Oracle 10g中unique與index的問題
create table test
(
x integer,
y integer,
z integer
);
alter table test add constraint primary key (x); --產生一個約束,併產生一個同名索引
create unique index index01 on test(x,y);
--create unique index index02 on test(x,y); --不允許完全相同的索引,即使索引名稱不同
create unique index index03 on test(y,z);
create unique index index04 on test(z,y); --index04 是與index03互不相同的索引
alter table test add constraint cons01 unique(x,y,z) ; --產生一個約束,並自動產生一個名為cons01 的UNIQUE索引
alter table test add constraint cons01 unique(x,y) ; --產生一個約束,但因與index01 重複(自動產生的索引不區分順序),因此不能自動產生索引
alter table test add constraint cons01 unique(y,x) ; --產生一個約束,但因與index01 重複,因此不能自動產生索引
--create unique index cons01 on test(x,y); --不能執行,因為索引cons01 已經被約束cons01 自動建立的索引佔用
alter table test add constraint cons012 check (x>100);
alter table test add constraint cons013 check (x>100); --check可以內容完全相同
處理辦法:
提取所有約束(UCPR)
提取名稱不在約束表中的所有索引