Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Binary Relationship in Database
A Binary Relationship is a relationship between two different entities in a database. It maps the role group of one entity with the role group of another entity, establishing how data in one table relates to data in another table. There are three types of cardinalities for binary relationships − One-to-One (1:1), One-to-Many (1:N), and Many-to-Many (M:N).
One-to-One (1:1)
In a one-to-one relationship, one instance of the first entity is mapped with only one instance of the second entity. The primary key of one entity is available as a foreign key in the other entity. This type of relationship is less common in database design.
Example − Consider two entities Person and Driver_License. One person can have only one driving license, and one driving license belongs to only one person. The relationship from Driver_License to Person is mandatory (every license must belong to someone), but the relationship from Person to Driver_License is optional (not everyone has a driving license) ?
One-to-Many (1:N)
In a one-to-many relationship, one instance of the first entity is related to multiple instances of the second entity, but each instance of the second entity is related to only one instance of the first entity. This is the most common type of relationship in relational databases.
Example − Consider two entities Department and Employee. One department can have many employees working in it, but each employee belongs to only one department ?
Many-to-Many (M:N)
In a many-to-many relationship, one instance of the first entity is related to multiple instances of the second entity, and one instance of the second entity is related to multiple instances of the first entity. This type of relationship always requires a junction table (also called bridge table or associative table) to store the associations between the two entities.
Example − Consider two entities Student and Course. Many students can enroll in a course, and many courses can be taken by a student. A junction table Enrollment tracks which students are enrolled in which courses ?
Conclusion
Binary relationships are fundamental to database design and connect two entities with three possible cardinalities: 1:1 (one-to-one), 1:N (one-to-many), and M:N (many-to-many). Understanding these relationship types is crucial for proper database normalization and efficient data storage. Remember that many-to-many relationships always require a junction table to resolve the relationship into two one-to-many relationships.
