您不能具有带有唯一索引的非唯一值。但是,您可以具有带有由非唯一索引强制执行的唯一约束的非唯一值。即使您最初创建了一个非唯一索引,除非您在本节中提供了更多详细信息,否则
dropindexand
enable语法将尝试重新创建一个唯一索引
using index。
例如:
SQL> create table my_table(my_column number, 2 constraint my_constraint unique (my_column));Table created.SQL> alter table my_table disable constraint my_constraint drop index;Table altered.SQL> insert into my_table select 1 from dual union all select 1 from dual;2 rows created.SQL> alter table my_table enable novalidate constraint my_constraint;alter table my_table enable novalidate constraint my_constraint*ERROR at line 1:ORA-02299: cannot validate (USER.MY_CONSTRAINT) - duplicate keys foundSQL> alter table my_table enable novalidate constraint my_constraint 2 using index (create index my_index on my_table(my_column));Table altered.SQL> --The constraint is enforced, even though other rows violate it.SQL> insert into my_table values(1);insert into my_table values(1)*ERROR at line 1:ORA-00001: unique constraint (USER.MY_CONSTRAINT) violated



