Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> How to update child tables using trigger?

How to update child tables using trigger?

From: Kirmo Uusitalo <kirmo.uusitalo_at_iki.fi>
Date: 1997/08/05
Message-ID: <33e6f5ea.16941380@news.sci.fi>#1/1

Hi SQL gurus,

I have the following database. I wish to implement a trigger in the master table k_node that updates the dependent child table records on master table delete.

create table k_node(

  ID                NUMBER(38) NOT NULL primary key

);

create table k_line(
  ID NUMBER(38) NOT NULL primary key,
  INPUT_NODE NUMBER(38),
constraint fk_input_node foreign key (input_node) references k_node(id)
);

create or replace trigger k_node_rd
before delete on k_node
for each row
begin
  update k_line set input_node=NULL where input_node=:old.id; end;
/

This is what happens:

SQL> insert into k_node values (1);

1 row created.

SQL> insert into k_line values (100,1);

1 row created.

SQL> delete from k_node where id=1;
delete from k_node where id=1

            *
ERROR at line 1:
ORA-04091: table SCOTT.K_NODE is mutating, trigger/function may not see it
ORA-06512: at line 2
ORA-04088: error during execution of trigger 'SCOTT.K_NODE_RD'

If I drop the foreign key constraint fk_input_node from k_line table, then the trigger executes OK. If someone could suggest a method to achieve this kind of functionality without losing the referential data integrity, I'd be more than happy.

Thank you all,

Kirmo.Uusitalo_at_iki.fi                   Key Technologies Oy 
System Analyst                          Uotinmaenkuja 9
tel. +358-9-323451,+358-500-439125      00970  HELSINKI
fax         324031                      FINLAND
Received on Tue Aug 05 1997 - 00:00:00 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US