novalidate with error ora-02299

允我心安 提交于 2019-12-01 08:25:51

问题


can anybody help with me with this?

id | Name
--------
1  | aaa
2  | bbb
3  | aaa

>alter table arc add CONSTRAINT uk_arc UNIQUE (NAME) novalidate
 error :ora-02299: cannot validate( .uk_arc ) - duplicate keys found

I am using novalidate to ignore the old duplicate and start to validate all over again.


回答1:


If I get you correctly, you expect Oracle to ignore old duplicate values and allow new values only when they satisfy the constraint. The error is returned because when you add a UNIQUE constraint, Oracle creates unique index on the column to check the values, but your table already have duplicate values, so it fails. I would create the non-unique index first, then add the constraint so that it uses your existing non-unique index instead of automatically creating the unique index which would fail:

create index arc_ix on arc (name);

alter table arc add constraint arc_uq unique (name) enable novalidate;


来源:https://stackoverflow.com/questions/17163580/novalidate-with-error-ora-02299

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!