Foreign key problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • diamond1
    New Member
    • Nov 2006
    • 7

    Foreign key problem

    Hi

    I have a problem with the Foreign key in Postgres 8.1 under Windows XP for example:
    I have PERSON table as a superclass and
    PERSON_A, PERSON_B, PERSON_C as subclasses
    Table_X as an ordinary table
    Then I want to link Table_X with PERSON_B, PERSON_C tables
    with a Foreign key which is id_no which is PK in the PERSON_B, PERSON_C tables

    (I had used inheritance, and I stored the data in the last subclasses for each superclass in my DB)

    So, when I want to store the id_no=3 in the Table_X it says that id_no=3 is not exist in the PERSON_B which is actually in PERSON_C table :chomp:

    Then I tried to link the id_no in the Table_X with PERSON table (superclass)

    it says that id_no=3 is not exist in the PERSON table :chomp:

    So, what I have to do?
  • archulu
    New Member
    • Mar 2007
    • 34

    #2
    i think this is usefull for u to how to call forghn key in another tables


    for primary key assighn ex:
    CREATE TABLE Leavetable ( emp_code varchar(25) primary key NOT NULL, fdate date, update date, first_half date, second_half date, no_of_days integer [3] );

    for foreighn key asighn ex:
    CREATE TABLE Leavetype ( emp_code varchar(25) references leavetable(emp_ code), date date, type_of_leave varchar, reason char [50] );

    Comment

    • michaelb
      Recognized Expert Contributor
      • Nov 2006
      • 534

      #3
      Originally posted by diamond1
      Hi

      I have a problem with the Foreign key in Postgres 8.1 under Windows XP for example:
      I have PERSON table as a superclass and
      PERSON_A, PERSON_B, PERSON_C as subclasses
      Table_X as an ordinary table
      Then I want to link Table_X with PERSON_B, PERSON_C tables
      with a Foreign key which is id_no which is PK in the PERSON_B, PERSON_C tables

      (I had used inheritance, and I stored the data in the last subclasses for each superclass in my DB)

      So, when I want to store the id_no=3 in the Table_X it says that id_no=3 is not exist in the PERSON_B which is actually in PERSON_C table :chomp:

      Then I tried to link the id_no in the Table_X with PERSON table (superclass)

      it says that id_no=3 is not exist in the PERSON table :chomp:

      So, what I have to do?
      Your error looks like a simple foreign key violation.
      Read the Foreign Keys section in this man page and also look at the Foreign Keys

      If you still has questions after that, please post your table definitions.

      Comment

      Working...