If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Alter table causing issues on creating FK to the existing table

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-29-10, 00:24
dbsam dbsam is offline
Registered User
 
Join Date: Dec 2009
Posts: 31
Alter table causing issues on creating FK to the existing table

Hi,

I am on version 9.7.2 of db2 on LUW. I am trying to create a Foreign Key on already exisiting table to the primary key of a newly created table. The already existing table was altered to add a new column with the same definition as the primary key of the new table.

I am getting this error when I try to create the FK relationship

SQL0667N The FOREIGN KEY "CTE_FK01" cannot be created because the table
contains rows with foreign key values that cannot be found in the parent key
of the parent table. SQLSTATE=23520

Initially the Primary key was defaulted to BLANK, but I removed that option.
Please advice. The developers need it from me as urgent and I have been working on this for a while now. I cant think of anything else

Thanks

DBSAM

Last edited by dbsam; 09-29-10 at 07:40.
Reply With Quote
  #2 (permalink)  
Old 09-29-10, 01:24
Mathew_paul Mathew_paul is offline
Registered User
 
Join Date: Oct 2007
Posts: 200
actually already the data which is there in child table for the foreign key is not matching with the parent tables primary key
regds
Paul
Reply With Quote
  #3 (permalink)  
Old 09-29-10, 07:40
dbsam dbsam is offline
Registered User
 
Join Date: Dec 2009
Posts: 31
Hi Paul,

The child table has data in it because it is an old table, but the new table or the parent table doesn't have any data in it yet. Also the new column(to be defined FK to the PK column of the new table) in the child table has been defined as default '' (BLANK) similar to the primary key column in the parent table. I am wondering if there is any workaround fro this kind of situation. Please let me know

DBSAM
Reply With Quote
  #4 (permalink)  
Old 09-29-10, 08:05
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
Before you create the FK on the old table, populate the new table with the values that already exist in the old table.

Andy
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On