0 11

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:

  1. Create a relation for each participating entity.
  2. Identify the entity on the 1-side and the entity on the N-side.
  3. Add the primary key of the 1-side entity as a foreign key in the N-side relation.
  4. 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_No is 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:

  1. Create a relation for each participating entity.
  2. Create a new relation for the relationship itself.
  3. Include the primary keys of both participating entities as foreign keys in the new relation.
  4. The combination of these foreign keys usually forms the composite primary key of the new relation.
  5. 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_ID is a foreign key referencing STUDENT
  • Course_ID is a foreign key referencing COURSE
  • (Stu_ID, Course_ID) together form the composite primary key of ENROLLMENT
  • Enroll_Date is a relationship attribute included in the new relation

Summary Table

RelationshipMapping StrategyWhere FK is Placed
1:NForeign Key MethodFK added to the N-side relation
N:MNew Junction RelationNew 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.