March 3, 2009 at 7:41 am
Hi Peeps,
I have two tables that have a PK and FK relationship.
Now the idea is that the parent table (with the PK) is first loaded with data.
When I want to insert into the other table (with the FK), i expect the database server to check to ensure the the new record in the FK table is not an 'orphan'. which implies that if i have (say) a product_id = 5 in the first table and i try to enter data in the second table with FK = 5 , there should be no problem.
The problem is this, that it is not working that way.
It keeps giving me an error message that PK-FK relationship ...
I hope you've got my question.
Thanks
March 3, 2009 at 8:31 am
i guess more information is needed...
nothing gets handled automatically for you as far as PK/FK's go....you might not be doing things in the right order of operation.
did you add new product 5 in VB, and then add the FK details, also in VB? show us the code that is adding to the db.
Lowell
March 3, 2009 at 10:09 am
I guess i'll take it from another point cos the code is spread around and quite complex.
Do i have to build a relationship between the tables in the database (i.e. explicitly stating PK and FK relationships) or is it just OK for me to know the kind of relationship I have with my tables?
Thanks
March 3, 2009 at 11:13 am
you must create the tables with the PK's and FK's...otherwise what you stated....inserting 5 into the child table without checking that the 5 exists in the parent table could occur...that's what you want.
Lowell
March 4, 2009 at 4:38 am
Thanks Lowell,
I've discovered the problem. The variable i was using to enter ID was being changed in another subroutine and so was conflicting with what i already had in the PK table.
Thanks for your comments and advise (i was really going to remove the relationship between the tables)
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy