Using a trigger would be a good way of managing this task. I would place an INSERT or UPDATE conditional trigger on the WAPPLICANT table.
Setting Up Constraints and Auto-Sequenced ID/Key Columns
The values BAID, BAPPID and APPID can be managed through 3 individual Primary Key constraints. If you designed these tables through APEX, you can let Oracle manage the assignment of new index/key values:
- In the create table wizard, when prompted for PRIMARY KEY, Choose "Populated from a New Sequence".
- Select the column value you have designated as the Index/Key for the specific table you're creating.
- You may designate a FOREIGN KEY constraint since there is a connection between the different columns in your tables. It's good practice to make them because it prevents the possibility of orphaned records, like an appointee or a board appointment without an matching application.
If you choose to create a Foreign Key, the order that you create the tables matters... a REFERENCED Primary Key has to exist before a Foreign Key can be created to point to it. If you miss that detail, you can always alter the tables or modify them to add the FK's at a later time.
Setting Up The Trigger
Since The two additional tables are not initially populated by user input, these both can be initialized with their own block of PL/SQL code... in this example, I just stuff it into the trigger... though I advise future caution with putting too much code or logic into triggers... they can kill performance and even lock up other DML operations against the table if the trigger takes to long to finish up.
We will use the trigger to capture the BAPPID value, which you indicate is needed in the other two tables. These are the settings you should designate when creating your trigger through the Apex interface:
- Build the trigger on table WAPPLICANT
- Firing Point: AFTER
- Options: INSERT, UPDATE (I assumed it is possible to insert an application in Accepted status.)
- When: NEW.BAPPSTATUS = 'Accepted'
- "For Each Row" (selected)
Trigger Body: (see code snippet below. The Apex "Create Trigger" dialogue will fill in most of the customary syntax...)
INSERT INTO APPOINTEES ( APPID, APPFNAME, APPLNAME, APPSUF, APPDOB... ) VALUES ( :NEW.BAPPID, :NEW.BAPPFNAME, :NEW.BAPPLNAME, :NEW.APPSUF, :NEW.APPDOB ...); INSERT INTO BRDAPPT ( BRDID, BRDAPT, BRDAPPDATE... ) VALUES ( :NEW.BAPPBID, :NEW.BAPPID, :NEW.BAPPTBDATE... );
A "COMMIT" statement is not necessary within the PL/SQL block of your trigger body. Remember, any Primary Key values that you have associated with a sequence does not need to be included within any of the INSERT commands within your PL/SQL as Apex has actually set up an auto-sequencing trigger for you.
That's it.