20:03:08 SQL> alter table norm2 add constraint norm2_fk 20:03:13 2 foreign key (id) references norm1(id) 20:03:19 3 initially deferred; alter table norm2 add constraint norm2_fk * ERROR at line 1: ORA-02298: cannot validate (JXA.NORM2_FK) - parent keys not found 20:03:24 SQL> alter table norm2 add constraint norm2_fk 20:11:20 2 foreign key (id) references norm1(id) 20:11:23 3 enable novalidate; Table altered. 20:11:37 SQL>Teraz można sprawdzić jak wyglądają te constrainty. Nowy klucz obcy jest właczony. Sprawdzanie ma miejsce, ale jest caly czas w stanie "NOT VALIDATED".
20:32:04 SQL> / CONSTRAINT_NAME STATUS DEFERRED VALIDATED ------------------------------ -------- --------- ------------- [...] NORM2_FK ENABLED IMMEDIATE NOT VALIDATED 20:32:42 SQL> list 1 select constraint_name,status,deferred,validated 2* from user_constraints where table_name = 'NORM2'Właczenie nie jest możliwe jak widać na poniższym listingu:
20:32:46 SQL> alter table norm2 modify constraint norm2_fk enable validate; alter table norm2 modify constraint norm2_fk enable validate * ERROR at line 1: ORA-02298: cannot validate (JXA.NORM2_FK) - parent keys not found 20:35:30 SQL>Można jednak sprawdzić, które wiersze są przyczyną łamania zależności klucza obcego. Najpierw tworzymy table exceptions, potem uruchamiamy jeszcze raz powyższe polecenie z klauzulą "EXCEPTIONS INTO":
20:38:54 SQL> @?/rdbms/admin/utlexcpt Table created. 20:38:57 SQL> alter table norm2 modify constraint norm2_fk 20:39:08 2 enable validate exceptions into exceptions; alter table norm2 modify constraint norm2_fk * ERROR at line 1: ORA-02298: cannot validate (JXA.NORM2_FK) - parent keys not found 20:42:10 SQL> select * from exceptions; ROW_ID OWNER TABLE_NAME CONSTRAINT ------------------ ---------- ---------- ---------- AAAA9oAADAAABwDAAC JXA NORM2 NORM2_FK 20:42:17 SQL>Przyjemne, prawda? Można w ten sposob dokładnie dojść które wiersze psują integralność tabeli i włączyć więzy.