By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,871 Members | 2,418 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,871 IT Pros & Developers. It's quick & easy.

Foreign key problem

diamond1
P: 7
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?
Apr 17 '07 #1
Share this Question
Share on Google+
2 Replies


archulu
P: 34
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] );
Apr 18 '07 #2

Expert 100+
P: 534
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.
Apr 18 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.