There's one question that bothers me all the time,i'll try to explain in it by simple example.
Lets say i have baskets,i've created table for them:
BasketID, int (PK)
BasketNumber, String
BoxID
I also gave carton boxes and i've also created tables for them:
BoxID, int (PK)
BoxNumber, String
AppleID
And i have plenty of apples or i will gather them and the table is:
AppleID, int (PK)
NumberofApples, String
Now what puzzles me is this...i will put at least one apple in each carton box(there's place for 4 apples at all),but i can also put there 2,3 or 4 apples,based on some circumstances.
And i'll place those boxes then in baskets.The number of boxes in each basket will differ(it can be one box,two,three..ten...twenty and etc).
Now based on my related tables description it will look something like this:
BasketID 1
BasketNumber 1
BoxID 1
BoxID 1
BoxNumber 1
AppleID 1
NumberofApples 3
So by these definitions you can say that there's Basket no.1 in it there's Box no.1 and there's 3 apples in the box itself.
Everything seems ok here to me,but when i want to add another box to this basket i get puzzled...so how will this look?Since there's one foreign key(BoxID) and i'll relate one more of the same table(BoxID),just probably with another values in there.How will it separate those BoxID collumns one from each other?It can't look like this:
BasketID 1
BasketNumber 1
BoxID 1
BoxID 2
BoxID 1 BoxID 2
BoxNumber 1 BoxNumber 2
AppleID 1 AppleID 2
AppleID 1 AppleID 2
NumberofApples 3 NumberofApples 1
As i understand,it should be done somehow other way?Since there is appearing two same collumns(BoxID),just the values are different...I can't put two same collumns in Basket definition table(BoxID int (FK),BoxID int (FK)) or can i?
What am i missing here?
I'm doing all this with Visual Basic 2008 Express and SQL Express.