Forum Stats

  • 3,837,474 Users
  • 2,262,262 Discussions


Using Trigger to Populate Data in One Table with Data From Another

MAFinanceDev-Oracle Member Posts: 13
edited Nov 19, 2015 5:51PM in APEX Discussions

Hi All,

I have three tables (TABLE_1, TABLE_2, & TABLE_3). I have a trigger on TABLE_1 that, when fired, inserts data from one column in TABLE_3 into TABLE_2. This trigger is fired when a new record is created on TABLE_1. This results in new records being added on TABLE_2 (3 to be exact). Additionally, when a new record is created on TABLE_1, a primary key (called PROJECT_ID) is automatically generated for the new record on TABLE_1.

Now what I need to do is create a trigger that will insert the primary key (PROJECT_ID) from the new record created on TABLE_1 to each of the new records created on TABLE_2 in the corresponding PROJECT_ID column when the first trigger is fired. The new records on TABLE_2 should all have the same PROJECT_ID matching the one created in TABLE_1.

Any help with the SQL code on this would be very helpful and also advice on what table the 2nd trigger should be added to.

Here is the code for the first trigger.  What can I add to make that PROJECT_ID column on TABLE_2 populate with the PROJECT_ID from TABLE_1?

create or replace trigger "TABLE_1_TRIGGER"


insert on "TABLE_1"


insert into TABLE_2



from TABLE_3;




  • TexasApexDeveloper
    TexasApexDeveloper Member Posts: 7,941 Gold Crown
    edited Nov 19, 2015 5:51PM

    Can you have a separate trigger fire?  Since you are doing this BEFORE INSERT, you will not know the PROJECT_ID until after the row is inserted.. I believe this was noted in an earlier thread you posted..

    Thank you,

    Tony Miller
    Los Alamos, NM

This discussion has been closed.