DBMS slides 📂 Introduction · 5 of 11 42 min read

Converting an ER Model to a Relational Schema: The 7-Step Mapping Algorithm

🔄

Converting an ER Model to a Relational Schema

The 7-step algorithm that turns a conceptual ER diagram into real tables — entities become tables, attributes become columns, keys become primary keys, and relationships become foreign keys.
7-Step Algorithm Keys & Foreign Keys Junction Tables Worked Example

Press Next → or use ← → arrow keys

Section 01

The Story — Sketch to Builder's Worksheet

The architect hands off to the builder
An architect's sketch is beautiful, but a builder can't pour concrete from it — they need a precise worksheet with exact dimensions and materials. Converting an ER diagram to a relational schema is the same hand-off: it bridges what designers mean (the conceptual ER diagram) and what developers build (the logical set of tables).
💡
The Central Principle

Entities become tables, attributes become columns, keys become primary keys, and relationships become foreign keys. Master that one sentence and the rest is detail.

Section 02

The Big Picture — Conceptual → Logical

ER ConstructRelational Equivalent
Strong entityA table
Weak entityTable with the owner's key included
Simple attributeA column
Composite attributeOne column per leaf component
Multivalued attributeA separate table
Derived attributeUsually not stored
Key attributePrimary key
1:1 / 1:N relationshipForeign key (no new table)
M:N relationshipJunction table
Section 03

The Seven-Step Mapping Algorithm

1Strongentities 2Weakentities 31:1FK one side 41:NFK many side 5M:Njunction 6Multivaluedown table 7n-aryown table RELATIONALSCHEMA ✓
🧭
Why the Order Matters

Create all entity tables first (steps 1–2), then relationships (steps 3–5, 7) can reference tables that already exist. Attributes get flattened along the way (step 6). Build the boxes before you draw the arrows.

Section 04 · Step 1

Strong Entities Become Tables

STUDENT Roll_No Name Age maps to STUDENT Roll_No 🔑 Name Age key attribute → PRIMARY KEY · simple attributes → columns
CREATE TABLE STUDENT (
    Roll_No  INTEGER PRIMARY KEY,   -- key attribute
    Name     TEXT,
    Age      INTEGER
);
Section 05 · Attributes

Composite, Derived & Multivalued Attributes

🧩
Composite → leaf columns
Atomicity forbids one "Name" cell. Store one column per leaf, discard the root.
Name → First_Name, Last_NameAddress → House_No, City, PIN
Derived → don't store
Keep the base data, compute on demand in a query or view.
Age from DOB · Total = Qty × PriceExperience = today − Join_Date
📚
Multivalued → child table
A separate table with the owner's key (FK) + the value; the pair is the PK.
EMP_PHONE(Emp_ID, Phone_No)
-- Composite flattened + multivalued lifted into its own table
CREATE TABLE EMPLOYEE ( Emp_ID PRIMARY KEY, First_Name, Last_Name, House_No, City, PIN );
CREATE TABLE EMP_PHONE ( Emp_ID REFERENCES EMPLOYEE(Emp_ID), Phone_No,
                          PRIMARY KEY (Emp_ID, Phone_No) );

-- Derived: keep DOB, compute Age at query time
SELECT Roll_No, Name, FLOOR(DATEDIFF(CURRENT_DATE, DOB)/365.25) AS Age FROM STUDENT;
Section 05 · Multivalued

Why a Multivalued Attribute Needs Its Own Table

EMPLOYEE Phone_No double ellipse = many values EMPLOYEE Emp_ID 🔑 EMP_PHONE Emp_ID (FK) Phone_No PK = (Emp_ID, Phone_No) — one row per phone number
🚫
Never Cram a List Into One Column

Storing "9876…, 9123…" in a single Phone_No cell violates first normal form and breaks searching and updates. Lift it into a child table keyed by the owner instead.

Section 06 · Step 3

Mapping 1:1 Relationships

No new table. Put one entity's primary key into the other as a foreign key — prefer the side with total participation to minimise NULLs.

PERSON 11 HAS PASSPORT PASSPORT = totalparticipation → gets FK
CREATE TABLE PERSON   ( Person_Id PRIMARY KEY, Name );
CREATE TABLE PASSPORT ( Pass_No PRIMARY KEY, Issue_Dt,
                        Person_Id REFERENCES PERSON(Person_Id) UNIQUE );  -- 1:1 → UNIQUE FK
Section 07 · Step 4

Mapping 1:N Relationships

CUSTOMER 1N TAKES LOAN Cust_No copied here as FK → on the "many" side
CREATE TABLE CUSTOMER ( Cust_No PRIMARY KEY, Name, City );
CREATE TABLE LOAN (
    Loan_No PRIMARY KEY,
    Amount,
    Cust_No REFERENCES CUSTOMER(Cust_No)   -- FK on the "many" side, repeats freely
);
Never Put the Key on the "One" Side

The one customer would need many loan numbers stuffed into a single cell — impossible. The foreign key always goes on the many side, where it can repeat.

Section 08 · Step 5

Mapping M:N Relationships — Junction Table

STUDENT MN ENROLLS COURSE ENROLLS Roll_No FK Course_ID FK Grade
CREATE TABLE ENROLLS (
    Roll_No   REFERENCES STUDENT(Roll_No),
    Course_ID REFERENCES COURSE(Course_ID),
    Grade,                                -- relationship attribute lives here
    PRIMARY KEY (Roll_No, Course_ID)      -- composite key blocks duplicate enrolments
);
Section 09 · Step 2

Mapping Weak Entities

"Payment 2" is ambiguous across loans — only "Payment 2 of Loan L1" is unique. The weak entity borrows the owner's key.

LOAN PAYS PAYMENT PAYMENT( Loan_No FK, Payment_No, Pay_Date ) PK = (Loan_No, Payment_No)
🔑
Composite Key = Owner Key + Partial Key

Payment_No repeats across loans, but the pairs (L1, 1) and (L2, 1) stay distinct. Omit the owner's key and identical partial keys collide.

Section 10 · Step 7

Mapping n-ary Relationships

A relationship of degree 3 or more always becomes its own table, holding every participant's primary key as a foreign key, plus any descriptive attribute.

Ternary RelationshipResulting Table
DOCTOR – PATIENT – DRUG (PRESCRIBES)PRESCRIBES(Doctor_ID FK, Patient_ID FK, Drug_ID FK, Dose)
SUPPLIER – PROJECT – PART (SUPPLIES)SUPPLIES(Sup_ID FK, Proj_ID FK, Part_ID FK, Qty)
🔗
Same Logic as M:N — Just More Keys

An n-ary table is a junction table with three (or more) foreign keys. The combination of participant keys forms the primary key, and attributes like Dose or Qty belong to the whole triple.

Section 11 · Worked Example

A Complete University Schema

DEPARTMENTDept_ID 🔑 · Dname STUDENTRoll_No 🔑 · Name · Dept_ID FK COURSECourse_ID 🔑 · Title ENROLLSRoll_No FK · Course_ID FK · Grade STUDENT_PHONERoll_No FK · Phone_No 1:N (Dept→Student) · M:N (Student–Course via ENROLLS) · multivalued (phones)
DEPARTMENT   (Dept_ID PK, Dname)
STUDENT      (Roll_No PK, Name, Dept_ID FK)
COURSE       (Course_ID PK, Title)
ENROLLS      (Roll_No FK, Course_ID FK, Grade)     -- PK = (Roll_No, Course_ID)
STUDENT_PHONE(Roll_No FK, Phone_No)            -- PK = (Roll_No, Phone_No)
Section 12

Three Common Mistakes to Avoid

🗂️
Extra tables for 1:1 / 1:N
These need only a foreign key — no new table. Only M:N and n-ary relationships get their own table.
📋
Multivalued in one column
Cramming a list into a cell violates 1NF and breaks searching and updates. Lift it into a child table.
🔑
Weak entity without owner key
Omit the owner's key and rows with identical partial keys collide. The composite PK is mandatory.
🧭
The Litmus Test for a New Table

Ask: is it a strong entity, weak entity, multivalued attribute, M:N, or n-ary relationship? If yes → new table. Everything else is just a foreign key or a column.

Section 13 · Cheat Sheet

Quick Reference — Every Construct

ER ConstructMapping RuleNew Table?
Strong entityTable with key attribute as PKYes
Weak entityPK = owner PK + partial keyYes
Composite attr.One column per leafNo
Derived attr.Omitted — computed on demandNo
Multivalued attr.Child table keyed by ownerYes
1:1 relationshipFK on either side (prefer total)No
1:N relationshipFK on the many sideNo
M:N relationshipJunction table with both PKsYes
n-ary relationshipTable with all participants' PKsYes
Section 14 · Part 1

Golden Rules of Mapping — 1 to 3

🏆 NON-NEGOTIABLE RULES · 1–3
1
Entity-first. Create all entity tables before adding any foreign keys — relationships can only reference tables that already exist.
2
Every table needs a primary key. Strong entities bring their own; weak entities borrow the owner's and add a partial key.
3
1:N foreign key placement. The "many" side always receives the foreign key — never the "one" side.
Section 14 · Part 2

Golden Rules of Mapping — 4 to 6

🏆 NON-NEGOTIABLE RULES · 4–6
4
M:N and n-ary relationships get their own table. The presence of a relationship attribute (Grade, Qty, Dose) alone proves the table is necessary.
5
Enforce attribute atomicity. Flatten composites into leaf columns, omit derived attributes, and lift multivalued attributes into child tables.
6
Keep names consistent. A foreign key should echo the primary key it references — readable joins depend on it.
🧵
The Thread

Boxes first, arrows second. Give every table a key, put the FK on the many side, and give M:N and n-ary their own tables — do that and any ER diagram converts cleanly.

FINAL

From Diagram to Database

7Mapping steps
5"New table" constructs
FKOn the many side
M:N→ junction table
1NFAtomic columns only
🎯
The Foundation Is Set

You can now take any ER diagram and produce a correct set of tables — strong and weak entities, all three relationship types, n-ary relationships, and every attribute flavour. Next comes making those tables well-formed: functional dependencies and normalization (1NF → BCNF).

🧠
One Sentence to Remember

Entities → tables, attributes → columns, keys → primary keys, relationships → foreign keys — and only M:N, n-ary, weak entities and multivalued attributes earn a table of their own.

🔄 End of tutorial · Press to review, or click Restart