2.4 Step-by-Step Rules: Converting ER Diagrams into Relational Tables
💡 Core Intuition
🍳 The Everyday Analogy: Translating an Architect's Sketch into Brickwork
Imagine an architect sketching a dream home:
- The sketch uses circles, triangles, and dashed lines to depict rooms, doors, and shared balconies.
- However, bricklayers cannot build "diamonds" and "double ovals" out of concrete. They only know flat concrete slabs, walls, and doorways.
The ER diagram is the architect's conceptual sketch; Relational Tables (SQL relations) are the physical concrete walls and slabs.
- A simple room becomes a flat table.
- A shared doorway between two rooms becomes a Foreign Key.
- A multi-purpose hallway connected to ten different rooms becomes a separate junction corridor.
Table Reduction is the art of building this house with the minimum necessary walls—eliminating redundant tables without allowing moisture (data redundancy) or wall collapses (data anomalies) to occur.
💻 Bridging to Computer Science
Relational database management systems (like PostgreSQL, MySQL, and Oracle) do not store Peter Chen ER rectangles and diamonds directly. They store flat 2D relations (tables) governed by First Normal Form (1NF).
Every software engineer must know how to translate an ER conceptual schema into a mathematical set of normalized relations with the minimum number of tables. Creating too many tables causes massive JOIN performance bottlenecks, while creating too few creates severe NULL bloat.
📋 The Master ER-to-Relational Mapping Framework
Rule 1: Conversion of Strong Entity Sets
For each strong entity set, create an independent relation (table) containing all simple attributes.
- If an attribute is composite, include only its atomic sub-attributes.
- The primary key of the entity set becomes the Primary Key of the relation.
Rule 2: Conversion of Binary 1:1 Relationships
In a binary relationship between and , no separate table is required:
- One Side Total, One Side Partial:
Take the Primary Key of the partial participation side as a Foreign Key into the table on the Total Participation side!
Why? Because every tuple on the total participation side participates, resulting in zero
NULLvalues! - Both Sides Partial:
- Take the Primary Key of either side as a Foreign Key on the other side.
- Both Sides Total Participation:
Golden Table Reduction Invariant
- Both entity sets and , along with the relationship , can be merged into a single consolidated relation with zero NULLs.
Rule 3: Conversion of Binary 1:N or N:1 Relationships
In a binary relationship, no separate table is required.
Rule: Modify the table on the -side (Many-side) by adding the Primary Key of the -side as a Foreign Key on the -side. Any descriptive attributes of the relationship diamond are placed directly into the -side table.
Rule 4: Conversion of Binary M:N Relationships
In a binary relationship, a separate table is strictly required (Junction Table).
Rule: Take the Primary Keys of both participating tables and declare their combination (composite key) as the Primary Key of the new table:
Rule 5: Conversion of Multi-Valued Attributes
A multi-valued attribute always requires a separate table.
Rule: Take the multi-valued attribute and the Primary Key of the parent entity table (as a Foreign Key). The composite of both attributes forms the Primary Key of the new table:
Rule 6: Conversion of Weak Entity Sets
Convert every weak entity set into a separate table:
- The table includes all simple attributes of the weak entity plus the Primary Key of the identifying strong entity as a Foreign Key.
- The identifying relationship set is absorbed directly into the weak entity table (no third table needed).
- .
🧮 Step-by-Step Solved Numericals
Problem 1: Multi-Valued Attributes and 1:N Reduction
Problem Statement:
Consider the following entity relationship diagram (ERD), where two entities and have a relation of cardinality .
- The attributes of are and where is the key attribute.
- The attributes of are and where is the key attribute and is a multi-valued attribute.
- Relation does not have any attribute.
A relational database containing the minimum number of tables with each table satisfying the requirements of Third Normal Form (3NF) is designed from the above ERD.
Determine the minimum number of relational tables required to represent this schema.
Step-by-Step Mathematical Derivation:
-
Entity (1-side):
- Since is on the 1-side of a relationship, it forms an independent table:
-
Entity and Relationship (-side):
- By Rule 3, in a relationship, relationship is merged into the -side table () by taking the primary key of () as a foreign key:
-
Multi-Valued Attribute :
- By Rule 5, a multi-valued attribute cannot reside in without violating 1NF. It requires a dedicated separate table combining the primary key of with :
Problem 2: Dual Relationships (1:N and M:N) Between Same Entities
Problem Statement:
Let and be two entities in an E-R diagram with simple single-valued attributes.
and are two distinct relationships between and , where is One-to-Many () and is Many-to-Many ().
and do not have any attributes of their own.
Determine the minimum number of relational tables required to represent this complete schema without data redundancy.
Step-by-Step Mathematical Derivation:
- Entity (1-side of ):
- Requires Table 1:
- Entity and Relationship ():
- By Rule 3, is merged into (-side) by placing as a Foreign Key inside :
- Relationship ():
- By Rule 4, an relationship cannot be merged into either or . It strictly requires an independent cross-reference junction table:
🏭 In The Real World: Production Case Study
Slack Workspace Architecture: Resolving User-Channel Relationships
In team messaging systems like Slack or Discord, organizations deal with hundreds of millions of users participating in thousands of public and private chat channels.
The Problem: A user joins 80 channels; a channel contains 10,000 team members. This is a classic Many-to-Many () relationship.
Production Table Reduction: Slack implements the junction table channel_member(user_id, channel_id, role, last_read_timestamp):
- Acts as an associative entity storing relationship-specific states (
last_read_timestamp,is_muted). - Indexed with compound B+ trees on
(user_id, channel_id)and(channel_id, user_id)for sub-millisecond query performance in both directions.
🎯 Exam & Interview Pitfall Check
Question 1: When can a binary relationship be converted into a single relational table?
Answer:
A binary relationship can be merged into a single table if and only if both participating entity sets have Total Participation. If either side has partial participation, merging them into a single table will force numerous attributes to store NULL for entities that do not participate.
Question 2: How is a Multi-Valued Attribute converted into the relational model?
Answer:
A multi-valued attribute violates First Normal Form (1NF) if kept inside the parent entity table. Therefore:
- It is converted into a separate dedicated relation.
- The relation includes the parent entity's Primary Key as a Foreign Key, alongside the multi-valued attribute.
- The Primary Key of this new relation is the composite of .
- Trap 1: "Where does the Foreign Key go in a 1:1 relationship with partial participation?"
If entity has Total Participation and entity has Partial Participation, always place the Foreign Key into entity . Placing it in would result in NULLs for every entity in that does not participate. Placing it in guarantees that every row has a non-null foreign key value! - Trap 2: "Can an M:N relationship ever be reduced to 2 tables?"
Strictly No. In relational algebra, converting an relationship into 2 tables either violates 1NF (storing multi-valued lists in a single cell) or introduces catastrophic data duplication. It always requires 3 tables.