Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Insert Into Select to Insert Data from a PK Column to FK Column

Dj SteeleDec 7 2017 — edited Dec 8 2017

Hello

I am trying to Populate a FK Column( which is a Junction Table)  with Values from a PK Column

Desired Result:  To Populate the Junction Table Customer_ID FK  with the values of the PK Column in Customer_3 Table 

Parent Table

Create Table Customer_3 (

       Customer_ID             Number(10) Default 0,

Constraint Customer_3_Customer_ID_PK Primary Key (Customer_ID)

---------------------------------------------------------------------------------------------------------

Child Table

Create Table Customer_Accounts_3 (

   Customer_ID  Number(7) Default 0 Not Null,

   Account_ID   Number(7) Default 0 Not Null,

Constraint Customer_Accts_Cust_ID_FK_3 Foreign Key (Customer_ID)

  References Customer_3 (Customer_ID),

Constraint Customer_Accts_Acct_ID_FK_3 Foreign Key (Account_ID)

  References Accounts_3 (Account_ID));

----------------------------------------------------------------------------------------------------

Using this Insert Into Select query  But getting Error Below

Insert Into Customer_Accounts_3 (Customer_ID)

Select Customer_3.Customer_ID

From Customer_3

Where Customer_3.Customer_ID > 0

ORA-02291: integrity constraint (DS41.CUSTOMER_ACCOUNTS_3_CON) violated - parent key not found

There is a Third Table Accounts that has a FK  Account_ID  linking back to Customer_Accounts Junction Table Above

I dont think that should matter.

THANK YOU

Thanks in

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 5 2018
Added on Dec 7 2017
8 comments
651 views