【发布时间】:2011-11-23 05:21:15
【问题描述】:
有人能澄清一下没有唯一约束的唯一索引(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" 也会失败。
我完全被这种行为弄糊涂了。有没有约束?
有很多文章解释了为什么可以有一个没有唯一索引的唯一约束;这很清楚,而且很有意义。但是,我不明白没有约束的唯一索引的原因。
【问题讨论】:
标签: oracle unique-key