Results 1 to 4 of 4
  1. #1
    Join Date
    Dec 2009

    Unanswered: Alter table causing issues on creating FK to the existing table


    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


    Last edited by dbsam; 09-29-10 at 08:40.

  2. #2
    Join Date
    Oct 2007
    actually already the data which is there in child table for the foreign key is not matching with the parent tables primary key

  3. #3
    Join Date
    Dec 2009
    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


  4. #4
    Join Date
    Jan 2003
    Provided Answers: 5
    Before you create the FK on the old table, populate the new table with the values that already exist in the old table.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts