有人可以澄清没有唯一约束(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"
。我完全被这种行为弄糊涂了。有没有约束?
有很多文章解释了为什么可以有一个没有唯一索引的唯一约束;这很清楚,而且很有意义。但是,我不明白没有约束的唯一索引的原因。