Question : Trigger insert with constraint

I have 2 tables :


T1
------------
ID_1 PK


T2
------------
ID_2
ID_1  FK



I need a T1 trigger like :

if :NEW."ID_1" is null then
    select "T1_SEQ".nextval into :NEW."ID_1" from dual;
    insert into T2(ID_1) values (select "T1_SEQ".currval" from dual) ;
end if

but obviously I can't insert into T2 before T1 is created  :

ORA-02291: integrity constraint (SH.T2_FK) violated - parent key not found

Do I have any other option then removing FK constraint ?

Answer : Trigger insert with constraint

ie

Before insert trigger

if :NEW."ID_1" is null then
   select "T1_SEQ".nextval into :NEW."ID_1" from dual;
end if

after insert trigger

insert into T2(ID_1) values (:new.id_1) ;  


 

Random Solutions  
 
programming4us programming4us