Why ENABLE NOVALIDATE does not work?

DB version: 10 gr 2

I have a scenario in which I need to keep some duplicates in a table. I want to create a Unique key on this column, but double existing records should be ignored. I tried to ENABLE NOVALIDATE. But it does not work. Is there a workaround for this without deleting duplicate records?
create table roller (col1 number);

insert into roller values (1);
insert into roller values (1);
insert into roller values (2);
insert into roller values (3);

alter table roller add constraint uniq_roller unique (col1) ENABLE NOVALIDATE;

ERROR at line 1:
ORA-02299: cannot validate (IT_TOGO.UNIQ_ROLLER) - duplicate keys found

You can apply keys using nonunique indexes too. That seems to work in your case.

SQL> create index pk_non_uk on roller(col1);

Index created.

SQL>alter table roller add constraint uniq_roller unique (col1)
  2  using index pk_non_uk
  3  ENABLE NOVALIDATE
SQL> /

Table altered.

And this allows no new duplicates:

SQL> insert into roller values(3);
insert into roller values(3)
*
ERROR at line 1:
ORA-00001: unique constraint (TKO.UNIQ_ROLLER) violated
SQL>

Tags: Database

Similar Questions

Maybe you are looking for