Types of Relationships
Following are the types of relationships used in a database.
1. One-to-One Relationship
2. One-to-Many Relationship
3. Many-to-One Relationship
4. Many-to-Many Relationship
In One-to-One Relationship, one entity is related with only one other entity. One row in a table is linked with only one row in another table and vice versa.
For example: A student can have only one exam number
In One-to-Many relationship, one entity is related to many other entities.
One row in a table A is linked to many rows in a table B, but one row in a table B is linked to only one row in table A. For example: One Department has many staff members.
In Many-to-One Relationship, many entities can be related with only one in the other entity.
For example: A number of staff members working in one Department.
Multiple rows in staff members table is related with only one row in Department table.
A many-to-many relationship occurs when multiple records in a table are associated with multiple records in another table.
Example 1: Customers and Product
Customers can purchase various products and Products can be purchased by many customers
Example 2: Students and Courses
A student can register for many Courses and a Course may include many students
Example 3: Books and Student.
Many Books in a Library are issued to many students.