Discussions
Categories
- 196.9K All Categories
- 2.2K Data
- 240 Big Data Appliance
- 1.9K Data Science
- 450.4K Databases
- 221.7K General Database Discussions
- 3.8K Java and JavaScript in the Database
- 31 Multilingual Engine
- 550 MySQL Community Space
- 478 NoSQL Database
- 7.9K Oracle Database Express Edition (XE)
- 3K ORDS, SODA & JSON in the Database
- 546 SQLcl
- 4K SQL Developer Data Modeler
- 187.1K SQL & PL/SQL
- 21.3K SQL Developer
- 295.9K Development
- 17 Developer Projects
- 138 Programming Languages
- 292.6K Development Tools
- 107 DevOps
- 3.1K QA/Testing
- 646K Java
- 28 Java Learning Subscription
- 37K Database Connectivity
- 155 Java Community Process
- 105 Java 25
- 22.1K Java APIs
- 138.1K Java Development Tools
- 165.3K Java EE (Java Enterprise Edition)
- 18 Java Essentials
- 160 Java 8 Questions
- 86K Java Programming
- 80 Java Puzzle Ball
- 65.1K New To Java
- 1.7K Training / Learning / Certification
- 13.8K Java HotSpot Virtual Machine
- 94.3K Java SE
- 13.8K Java Security
- 204 Java User Groups
- 24 JavaScript - Nashorn
- Programs
- 443 LiveLabs
- 38 Workshops
- 10.2K Software
- 6.7K Berkeley DB Family
- 3.5K JHeadstart
- 5.7K Other Languages
- 2.3K Chinese
- 171 Deutsche Oracle Community
- 1.1K Español
- 1.9K Japanese
- 232 Portuguese
Using Trigger to Populate Data in One Table with Data From Another

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"
BEFORE
insert on "TABLE_1"
begin
insert into TABLE_2
(MILESTONE)
select MILESTONE
from TABLE_3;
end;
Answers
-
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