Posts tagged One-to-One
One-to-One Relationships
0A One-to-One relationship is a binary relationship. It occurs when one record in one entity references one record in the second entity.
Some modelers suggest that One-to-One relationships should be combined into a single entity, and that is usually considered best practice.
Implementation
The implementation is a little tricky; in order to enforce the semantics of a One-to-One relationship and avoid implementing a One-to-Many relationship we will have to put a unique index constraint in the foreign key.
In the diagram above, the STUDENT_ID foreign key in the STUDENT_DETAILS entity has a unique constraint which forces the DBMS to have only one row with that value. Without the unique constraint we would be allowing the database to have repeated STUDENT_ID values in the STUDENT_DETAILS entity and the relationship line would be out of synch with the actual implementation.
Alert:
When not to combine both entities:
- If you want better separation of information.
- If the two entities are managed by different owners.
- If the information in the referenced entity is optional and it can be null.
- If you anticipate the One-to-One relationship potentially becoming a One-to-Many.
Alert:
When to combine both entities:
- If you do not want to have an extra join in your queries.
- If the two entities are managed by the same group.
- If the information in the referenced entity is optional and it can be null (You would have come up with default values or allow for nulls).
- If you are completely sure that it will never become a One-to-Many.




