One-to-one mapping confusion
Why is it that a lot of people are referring to One-to-One when I am sure they are referring to Many-to-one?
For instance, if you have two tables;
Inventory (InventoryID)
Item (ItemID, InventoryFK)
There is no one-to-one mapping here as far as I can tell. It's "Many items to one inventory".
Now, let's assume that there would be only one item per inventory. In this case, my colleagues would start calling it a "one-to-one". Am I correct in pointing out that it's still a many-to-one relationship? When I try to explain this to them they don't seem to understand.
I believe a proper one-to-one mapping to be something like this:
Person (Column: PersonID, Name)
PersonAddress (Column: PersonID, StreetName, StreetNumber)
Here you'd have two tables, sharing the exact same PK.
Assuming my assumptions are correct, why are开发者_JAVA百科 so many people abusing the term "one-to-one"?
The one-to-many and one-to-one relation are implemented in a slightly different way.
One-to-many
Object (objectId) ObjectCharacteristics(charId,objectId)
One-to-one
The order of the table is not important:
Husband (husbandId) Wife(wifeId,husbandId) + unique constraint on husbandId
N.B. One-to-many relation is also a one-to-one relation in the order way. The ObjectCharacteristics has one and only one object.
But you are right the relationship is a concept that does not depend upon the specific data in your database but only on the structure of it.
I agree these terms are much abused. But who of us isn't guilty? Without knowing the constraints involved, your example of what you believe to be a one-to-one relationship could be a one-to-zero-or-one relationship (hint: the presence of a foreign key does not imply the presence of actual referencing values).
Chris Date wrote a very thorough analysis of the situation in his paper All for One, One for All.
精彩评论