BIT202 ยท 0 ยท 5 marks
During ER-to-Relational Mapping, show how you map 1:N and N:M relationship into a relation?
During ER-to-Relational Mapping, show how you map 1:N and N:M relationship into a relation? [5]
Database Management SystemChapter 4: ER to Relational MappingMapping one-to-many relationships
Quick answer
In a 1:N relationship between two entity types, the entity on the N-side (many-side) receives a foreign key that references the primary key of the entity on the 1-side (one-side).
ER-to-Relational Mapping: 1:N and N:M Relationships
1. Mapping 1:N (One-to-Many) Relationship
Approach: Foreign Key Method
Steps:
- Create a relation for each participating entity.
- Identify the entity on the 1-side and the entity on the N-side.
- Add the primary key of the 1-side entity as a foreign key in the N-side relation.
- Also include any attributes of the relationship in the N-side relation.
Example:
Consider: DEPARTMENT (1) ---- manages ---- (N) EMPLOYEE
DEPARTMENT (Dept_No, Dept_Name, Location)
EMPLOYEE (Emp_ID, Emp_Name, Salary, Dept_No)
โ
Foreign Key referencing DEPARTMENT
The foreign key
Dept_Nois placed in the EMPLOYEE relation (N-side).
2. Mapping N:M (Many-to-Many) Relationship
Approach: New Relationship Relation (Cross/Junction Table)
In an N:M relationship, a new relation (junction table) is created to represent the relationship. A direct foreign key approach is not sufficient here.
Steps:
- Create a relation for each participating entity.
- Create a new relation for the relationship itself.
- Include the primary keys of both participating entities as foreign keys in the new relation.
- The combination of these foreign keys usually forms the composite primary key of the new relation.
- Include any attributes of the relationship in the new relation.
Example:
Consider: STUDENT (N) ---- enrolls ---- (M) COURSE
STUDENT (Stu_ID, Stu_Name, Address)
COURSE (Course_ID, Course_Name, Credits)
ENROLLMENT (Stu_ID, Course_ID, Enroll_Date)
โ โ
FK FK
Stu_IDis a foreign key referencing STUDENTCourse_IDis a foreign key referencing COURSE- (Stu_ID, Course_ID) together form the composite primary key of ENROLLMENT
Enroll_Dateis a relationship attribute included in the new relation
Summary Table
| Relationship | Mapping Strategy | Where FK is Placed |
|---|---|---|
| 1:N | Foreign Key Method | FK added to the N-side relation |
| N:M | New Junction Relation | New relation with both PKs as FKs |
Short on time? The 1, 5 and 10 mark versions of this answer, flashcards and practice sets come with a program pass.