Home » Developer & Programmer » Forms » Insert a record into multiple table
Insert a record into multiple table [message #143833] Sun, 23 October 2005 02:22 Go to next message
sankar7
Messages: 7
Registered: October 2005
Location: Dhaka
Junior Member
Dear all,

Table a:

ID Varchar2(30), ---- Primary key
Name Varchar2(50),

Table B:

ID Varchar2(30), ---- Foreign key of table A;
B_Id varchar2(30), ---- Primary key;
Name ----

Now If I insert in table A , then this also insert into table B into id , name,


I have create this trigger but does not work

Create trigger aaaa
After insert on a
For each row

Declare
Temp_a_id varchar2(20),
Temp_b_id varchar2(20),
Temp_name varchar2(20),

Begin
Select id, name
Into temp_a_id, temp_name
From a
Where id = :new.id;

Select b_id
Into temp_b_id from b;
Temp_id :=temp_id +1;

Insert into b(id,b_id, name) values(temp_a_id, temp_b_id, temp_name);
End;

Can any one help me


Re: Insert a record into multiple table [message #143894 is a reply to message #143833] Mon, 24 October 2005 00:22 Go to previous message
djmartin
Messages: 10181
Registered: March 2005
Location: Surges Bay TAS Australia
Senior Member
Account Moderator
You probably want to use 'max(b_id)', as the current second 'select' probably returns multiple rows.

Also you can use the :new.id, and :new.name to populate your second 'insert' statement instead of doing the first 'select'.

David
Previous Topic: developer
Next Topic: query status (merged)
Goto Forum:
  


Current Time: Fri Sep 20 00:39:20 CDT 2024