Home » SQL & PL/SQL » SQL & PL/SQL » how to? on insert a record to parent > insert to child also
how to? on insert a record to parent > insert to child also [message #36128] Tue, 06 November 2001 23:37 Go to next message
Paul
Messages: 164
Registered: April 1999
Senior Member
when i insert a record to t1, it should automatically insert a record in t2 with t2.id = t1.id, and t2.name as null. is it possible to do it with TRIGGERS? or by any other means?
Help me, please.

create table t1
(
id varchar2(8) not null,
title varchar2(4),
constraint id_violation primary key (id)
);
commit;
create table t2
(
id varchar2(8) referencing t1 on delete cascade,
name varchar2(4)
);
commit;

----------------------------------------------------------------------
Re: how to? on insert a record to parent > insert to child also [message #36129 is a reply to message #36128] Wed, 07 November 2001 02:34 Go to previous messageGo to next message
Shilpa
Messages: 59
Registered: November 2001
Member
Try the following.

CREATE OR REPLACE TRIGGER schema.TRIGGERNAME AFTER INSERT
ON schema.T1 FOR EACH ROW
BEGIN
INSERT INTO T2(ID,NAME)
VALUES (:NEW.ID,NULL);
END;

----------------------------------------------------------------------
Re: how to? on insert a record to parent > insert to child also [message #36150 is a reply to message #36129] Wed, 07 November 2001 19:39 Go to previous messageGo to next message
Paul
Messages: 164
Registered: April 1999
Senior Member
thanks shilpa
but
since t2 is a child of t1, it says that "the table is mutating" _ error
what to do?

----------------------------------------------------------------------
Re: how to? on insert a record to parent > insert to child also [message #36159 is a reply to message #36129] Thu, 08 November 2001 03:41 Go to previous message
Shilpa
Messages: 59
Registered: November 2001
Member
Try the following.

CREATE OR REPLACE TRIGGER schema.TRIGGERNAME AFTER INSERT
ON schema.T1
BEGIN
INSERT INTO T2(ID,NAME)
VALUES (:NEW.ID,NULL);
END;

----------------------------------------------------------------------
Previous Topic: error PL/SQL select with database link
Next Topic: How to return a locally created PL/SQL table from a procedure
Goto Forum:
  


Current Time: Thu Mar 28 13:32:48 CDT 2024