ER to Relational Mapping is the process of converting an Entity–Relationship (ER) Diagram into a Relational Schema (tables) so that the database can be implemented in a relational DBMS (like MySQL, Oracle, SQL Server).
An ER diagram is a conceptual design, whereas a relational schema is a logical design. ER-to-relational mapping ensures that the conceptual model is correctly transformed into tables with proper keys and constraints.
ER Model → Relational Model involves 7 major steps:
Each strong entity becomes a table.
Attributes → Columns
Primary key → Primary Key of table
Entity: Student (RollNo, Name, Course)
Table:
Student(RollNo PK, Name, Course)
A weak entity depends on a strong entity and does not have its own primary key.
Create a table for the weak entity
Primary key = Partial key + Primary key of strong entity
Add foreign key referencing strong entity
Weak Entity: Dependent(Name, Age)
Strong Entity: Employee(EmpID)
Table:
Dependent(EmpID FK, Name, Age, Primary Key(EmpID, Name))
Two methods depending on the relationship type.
Add the primary key of one entity as a foreign key in the other
Prefer the entity with total participation
Person ↔ Passport
Person(PersonID PK, Name, PassportNo FK)
OR
Passport(PassportNo PK, PersonID FK)
Add the primary key of the "one" side as a foreign key in the "many" side.
Department(DeptID PK)
Employee(EmpID PK, Name, DeptID FK)
Create a separate table for the relationship
Primary key = Combination of both entity keys
Additional attributes of the relationship also added
Student —< Enroll>— Course
Enroll(StudentID FK, CourseID FK, Grade)
Primary Key(StudentID, CourseID)
Create a new table
Include multivalued attribute + primary key of the entity
Primary key = combination
Student(RollNo PK, Name)
Phones(RollNo FK, PhoneNumber, PK(RollNo, PhoneNumber))
Break into simple attributes
Do not create separate tables
Address = (HouseNo, City, State)
Stored as:
Address_HouseNo, Address_City, Address_State
Student(StudentID, Name)
Course(CourseID, Title)
Student —< Enroll>— Course
Enroll has attributes: Date, Grade
Student Table
Student(StudentID PK, Name)
Course Table
Course(CourseID PK, Title)
Enroll Table
Enroll(StudentID FK, CourseID FK, Date, Grade,
Primary Key(StudentID, CourseID))
Converts conceptual design into implementable schema
Ensures correct primary & foreign key placement
Eliminates redundancy
Preserves all constraints (1:1, 1:N, M:N)
Ensures logical consistency and integrity
ER to Relational Mapping is a systematic process that converts high-level ER models into relational schemas. By following rules for entities, relationships, keys, attributes, and constraints, we can design a structured and efficient relational database. This process ensures that the database remains consistent, accurate, and easy to manage when implemented in SQL-based systems.
Take quizzes related to this topic and see where you stand!
Start Quiz Now