Oracle
 sql >> Database >  >> RDS >> Oracle

Impossibile convalidare, con opzione novalidate

Non puoi avere valori non univoci con un indice univoco. Ma puoi avere valori non univoci con un vincolo univoco imposto da un indice non univoco. Anche se inizialmente hai creato un indice non univoco, l'drop index e enable la sintassi proverà a ricreare un indice univoco a meno che tu non fornisca maggiori dettagli in using index sezione.

Ad esempio:

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