Violate a foreign key
SQL> SQL> create table p ( pk int primary key ) 2 / Table created. SQL> create table c 2 ( fk constraint c_fk 3 references p(pk) 4 deferrable 5 initially immediate 6 ) 7 / Table created. SQL> insert into p values ( 1 ); 1 row created. SQL> insert into c values ( 1 ); 1 row created. SQL> SQL> update p set pk = 2; update p set pk = 2 * ERROR at line 1: ORA-02292: integrity constraint (JAVA2S.C_FK) violated - child record found SQL> SQL> set constraint c_fk deferred; Constraint set. SQL> SQL> update p set pk = 2; 1 row updated. SQL> SQL> set constraint c_fk immediate; set constraint c_fk immediate * ERROR at line 1: ORA-02291: integrity constraint (JAVA2S.C_FK) violated - parent key not found SQL> SQL> update c set fk = 2; 1 row updated. SQL> SQL> set constraint c_fk immediate; Constraint set. SQL> SQL> drop table p; drop table p * ERROR at line 1: ORA-02449: unique/primary keys in table referenced by foreign keys SQL> drop table c; Table dropped. SQL> SQL>
1. | Create table with foreign key | ||
2. | Create a foreign key with more than one field | ||
3. | Referential Integrity Constraints | ||
4. | Add constraint foreign key references | ||
5. | Declaring a Foreign Key |