嗨,我正在插入一些日期做我的表.由于某些原因,我不得不禁用我的约束.约束与索引相关联.我用过这行代码:
ALTER TABLE my_table DISABLE CONSTRAINT "my_constraint" drop index
并且my_constraint处于禁用状态.
不,我想启用此约束,但在调用此行之后:
ALTER TABLE my_table ENABLE NOVALIDATE CONSTRAINT "my_constraint";\
我发现了一个错误:
ORA-02299: cannot validate (USER.my_constraint) – – duplicate keys found
解决方法
您不能拥有唯一索引的非唯一值.但是,您可以使用由非唯一索引强制执行的唯一约束来使用非唯一值.即使您最初创建了非唯一索引,drop index和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 found sql> 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