Subject | Foreign Key Question |
---|---|
Author | jaybirdbsu |
Post date | 2004-09-14T16:17:41Z |
Howdy,
I realize this is more than likely not a FB question but I am just
having a hard time getting this to work right. I am sure it is in
the way I am looking at the problem. Here is what I have in some
generic terms.
TableA has a Primary Key of Col1, Col2.
TableB has a Primary Key of Col1, Col2, Col3.
TableB has a Foreign Key defined as FOREIGN KEY(Col1, Col2)
REFERENCES TableA(Col1,Col2).
Col1 and Col2 are the same type and size in both tables.
Here is where I am running into problems. They tables both CREATE
just fine. I am loading a bunch of data in from a text file and I
load TableA first and it works just fine. Then part way through
loading TableB I get a Foreign Key error. The interesting thing
about the row that generates the error is that it is the first row
that the Col2 data is duplicated, but the Col1 values are
different. I don't know if this is making sense. What I am
expecting from the foreign key may be incorrect. I am expecting
that it is requireing uniqueness on the combination of the two
columns. The combination of Col1 and Col2 are unique in this case
that is generating the error. I have searched the text files I am
loading the data from to make sure this is the case.
Can anyone help shed a bit of light on this? I would really
appreciate it.
Thanks in advance
Jay
I realize this is more than likely not a FB question but I am just
having a hard time getting this to work right. I am sure it is in
the way I am looking at the problem. Here is what I have in some
generic terms.
TableA has a Primary Key of Col1, Col2.
TableB has a Primary Key of Col1, Col2, Col3.
TableB has a Foreign Key defined as FOREIGN KEY(Col1, Col2)
REFERENCES TableA(Col1,Col2).
Col1 and Col2 are the same type and size in both tables.
Here is where I am running into problems. They tables both CREATE
just fine. I am loading a bunch of data in from a text file and I
load TableA first and it works just fine. Then part way through
loading TableB I get a Foreign Key error. The interesting thing
about the row that generates the error is that it is the first row
that the Col2 data is duplicated, but the Col1 values are
different. I don't know if this is making sense. What I am
expecting from the foreign key may be incorrect. I am expecting
that it is requireing uniqueness on the combination of the two
columns. The combination of Col1 and Col2 are unique in this case
that is generating the error. I have searched the text files I am
loading the data from to make sure this is the case.
Can anyone help shed a bit of light on this? I would really
appreciate it.
Thanks in advance
Jay