有人可以澄清沒有唯一約束(Oracle)的情況下擁有唯一索引的目的是什麼? 例如,Oracle唯一約束和唯一索引
create table test22(id int, id1 int, tmp varchar(20));
create unique index idx_test22 on test22(id);
insert into test22(id, id1, tmp) values (1, 2, 'aaa'); // ok
insert into test22(id, id1, tmp) values (1, 2, 'aaa'); // fails, ORA-00001: unique
// constraint (TEST.IDX_TEST22) violated
到目前爲止,它看起來像有一個約束。但是
create table test33(id int not null primary key,
test22_id int not null,
foreign key(test22_id) references test22(id));
也因爲"ORA-02270: no matching unique or primary key for this column-list"
而失敗。 我完全被這種行爲所困惑。有沒有約束?
有許多文章解釋了爲什麼可能有唯一的約束沒有唯一的索引;這是清楚的,非常有意義。但是,我不明白沒有約束的唯一索引的原因。
感謝您的回答,現在已經越來越清晰了。我真正不喜歡的是兩種情況下的相同錯誤代碼('ORA-00001'),約束和唯一索引。 – a1ex07
非常好,感謝您的「最終決定權」,感謝您是否可以在獨特的FBI上創建獨特的約束。 – orbfish
謝謝 - 這是我找到的兩個差異的唯一明確解釋。 我見過一些提到,聲明一個唯一的約束爲優化器提供了比唯一索引更多的信息...這是否是真的,這是否意味着一個獨特的約束可以在沒有約束的情況下爲獨特的索引提供一些性能優勢? – Mike