MODULE 02
DATABASE DESIGN — ER MODEL, RELATIONAL MODEL & NORMALIZATION
01
ER Model

Basic Concepts, Entities & Attributes

Proposed by Peter Chen, 1976

ER Model = Entity-Relationship Model. A high-level conceptual data model used to visually design databases before converting to relational tables. Three core concepts: Entities, Attributes, Relationships.

Entity Terminology

TermDefinitionExample
EntityA specific real-world object with independent existenceStudent 'Arun' (Roll 101)
Entity TypeCategory/class of similar entities — shown as RectangleSTUDENT
Entity SetAll entities of a type currently in DB (like a table)All enrolled students

Attribute Types — ER Notation

STUDENT Student_ID Key (underlined) Phone Multi-valued (double oval) Age Derived (dashed oval) Gender Simple (plain oval) Name Composite (sub-ovals) First Last
Attribute TypeDescriptionER NotationExample
Simple (Atomic)Cannot be divided furtherPlain ovalAge, Gender, Salary
CompositeCan be split into sub-partsOval with sub-ovalsName → First, Last
Single-ValuedOne value per entityPlain ovalDate_of_Birth, NID
Multi-ValuedMultiple values per entityDouble ovalPhone_Numbers, Degrees
DerivedComputed from other attributesDashed ovalAge (from DOB)
KeyUniquely identifies entityUnderlined ovalStudent_ID, EmpID

NULL Values

NULL is NOT zero, NOT empty string '', NOT a blank space. It means missing, unknown, or not applicable.
NULL TypeMeaningExample
MissingValue exists but unknownPhone number not collected
Not ApplicableAttribute irrelevant for this entitySpouse_Name for unmarried person

ER Diagram Notation — Complete Reference

ER ConceptNotation
Entity TypeRectangle
Relationship TypeDiamond
Simple AttributeOval (ellipse)
Key AttributeOval with underlined name
Multi-Valued AttributeDouble oval
Derived AttributeDashed oval
Composite AttributeOval with sub-ovals attached
Total ParticipationDouble line
Partial ParticipationSingle line
Weak Entity TypeDouble rectangle
Identifying RelationshipDouble diamond
Partial Key (Discriminator)Dashed underline
Exam tip: Double = weak/multi-valued. Dashed = derived/partial key. Underlined = key attribute. These distinctions are frequently tested.
02
Relationships

Relationships, Constraints & Weak Entities

Degree of a Relationship

DegreeDescriptionExample
Unary (1)Same entity type relates to itselfEMPLOYEE supervises EMPLOYEE
Binary (2)Two entity types — most commonSTUDENT enrolls in COURSE
Ternary (3)Three entity types simultaneouslySUPPLIER supplies PART to PROJECT

Cardinality Ratios (Mapping Cardinality)

Specifies max number of relationship instances an entity can participate in.
1 : 1 (One-to-One)
EMP manages DEPT 1 1
Each entity in A ↔ at most one in B
e.g. EMPLOYEE manages DEPARTMENT
1 : N (One-to-Many)
DEPT EMP 1 N
One in A → many in B
e.g. DEPARTMENT has many EMPLOYEES
M : N (Many-to-Many)
STUDENT COURSE M N
Many in A ↔ many in B. Requires junction table in relational model.
e.g. STUDENT enrolls in COURSE

Participation Constraints

ConstraintMeaningER NotationExample
Total (Mandatory)Every entity MUST participateDouble lineEvery EMPLOYEE works for a DEPT
Partial (Optional)Some entities may not participateSingle lineNot every EMP manages a DEPT

Weak Entity Types

A weak entity has no primary key of its own. Its existence depends on an owner entity via an identifying relationship.
EMPLOYEE Emp_ID HAS DEPENDENT Dep_Name Owner (strong) Weak entity (double rect)
AspectStrong EntityWeak Entity
Primary KeyHas its own PKNo PK — identified by Partial Key + Owner PK
ExistenceIndependentDepends on owner entity
ER NotationSingle rectangleDouble rectangle
RelationshipOrdinary diamondDouble diamond (identifying)
KeyPrimary key (solid underline)Partial key/discriminator (dashed underline)
ExampleEMPLOYEE (Emp_ID)DEPENDENT (Dep_Name + Emp_ID)
Extended ER (EER) — Specialization & Generalization
ConceptDirectionDescriptionExample
SpecializationTop-down ↓Define subclasses of a superclass (IS-A)EMPLOYEE → MANAGER, ENGINEER
GeneralizationBottom-up ↑Combine entities into a superclassCAR + TRUCK → VEHICLE
InheritanceSubclass inherits all superclass attributesMANAGER inherits all EMPLOYEE attrs
ConstraintSymbolRule
Disjoint'd' in circleEntity belongs to AT MOST one subclass
Overlapping'o' in circleEntity can belong to MULTIPLE subclasses
TotalDouble lineEvery superclass entity is in at least one subclass
PartialSingle lineSuperclass entity may not be in any subclass
Exam tip: Weak entity needs TWO things: double rectangle + double diamond. Partial key uses dashed underline. M:N relationships must be split into a junction/bridge table in relational schema.
03
Relational Model

Domains, Attributes, Tuples, Relations & NULLs

E.F. Codd, 1970

Proposed by E.F. Codd in 1970. Data is represented as a collection of relations (tables). Foundation of all RDBMS: MySQL, Oracle, PostgreSQL.

Core Terminology

TermDefinitionSQL equivalent
DomainSet of ALL possible atomic values for an attributeData type + constraints
Relation SchemaR(A1, A2…An) — name + list of attributes with domainsTable definition
RelationA set of tuples conforming to the schemaTable (with rows)
TupleA single row — ordered list of valuesRow / Record
AttributeA named column in the relationColumn
Degree (Arity)Number of attributes (columns)Number of columns
CardinalityNumber of tuples (rows) at a given timeRow count

Properties of a Relation — Must Know

  • No duplicate tuples — every row must be unique
  • No tuple ordering — order of rows doesn't matter
  • Atomic values — each cell holds ONE indivisible value (1NF requirement)
  • ℹ️ Attribute order matters for positional notation (not for named)
  • ℹ️ NULL values allowed unless constrained otherwise

NULL Values in Tuples

NULL ≠ 0  |  NULL ≠ ''  |  NULL ≠ ' '
NULL InterpretationExample
Unknown — value exists but not knownPhone number not provided
Not Available — value exists but not givenSalary withheld
Not Applicable — attribute irrelevantSpouse_Name for unmarried person
Any arithmetic with NULL → NULL. Any comparison with NULL → UNKNOWN (three-valued logic: TRUE / FALSE / UNKNOWN).
04
Constraints

Relational Model Constraints & Database Schemas

Key Types — Hierarchy

SUPERKEY — any set that uniquely identifies tuples CANDIDATE KEY — minimal superkey (no redundant attrs) PRIMARY KEY ALTERNATE KEY
Key TypeDefinitionProperties
SuperkeyAny set of attributes that uniquely identifies a tupleCan have extra/redundant attributes
Candidate KeyMinimal superkey — no redundant attributesRemoving any attr breaks uniqueness
Primary KeyChosen candidate key — official identifierNOT NULL + UNIQUE. Exactly one per table.
Alternate KeyCandidate keys NOT chosen as primaryEnforced via UNIQUE constraint in SQL
Foreign KeyReferences PK of another relationEnforces referential integrity

Four Main Integrity Constraints

1. Domain Constraint
Each attribute value must be atomic and from its defined domain.
Marks domain: INTEGER, 0–100. Storing 'Excellent' or 150 → rejected.
2. Key Constraint
Primary key values must be unique across all tuples.
No two students can have same Student_ID.
3. Entity Integrity Constraint
Primary key attribute(s) CANNOT be NULL. Must be able to identify every tuple.
Student_ID cannot be NULL — how would we identify the student?
4. Referential Integrity Constraint (Foreign Key)
A foreign key value must either match an existing PK value in the referenced relation, or be NULL.
STUDENT.Dept_ID must exist in DEPARTMENT.Dept_ID — no orphan records.

Operations & Possible Violations

OperationCan Violate
INSERTDomain, Key, Entity Integrity, Referential Integrity
DELETEReferential Integrity (if other tables reference this row)
UPDATEDomain, Key, Entity Integrity, Referential Integrity
Exam tip: Every PK is a Candidate Key but not vice versa. Every Candidate Key is a Superkey but not vice versa. Entity Integrity = PK cannot be NULL. Referential Integrity = FK must exist in referenced table.
05
Normalization

1NF, 2NF, 3NF, BCNF

Reduce redundancy, eliminate anomalies

Normalization = organizing a relational DB to reduce data redundancy and improve data integrity by applying progressive normal form rules.

Why Normalize? — The 3 Anomalies

AnomalyProblemExample
UpdateSame data in many rows — update one, others become inconsistentFaculty dept change must update every course row
InsertCan't add data without also adding unrelated dataCan't add dept unless a student is enrolled
DeleteDeleting one thing accidentally removes other infoDelete last student → course info also lost

Functional Dependency (FD)

X → Y means "X determines Y" — for any two tuples with same X value, Y must also be same.
FD TypeDefinitionExample
Full FDY depends on the ENTIRE composite key (not a subset)Grade depends on {Student_ID, Course_ID}
Partial FDY depends on only a PART of a composite keyStudent_Name depends only on Student_ID (part of key)
Transitive FDX→Y and Y→Z therefore X→Z (via intermediate)Student_ID → Dept_ID → Dept_Name

Normal Form Progression

Unnormalized (UNF) — has repeating groups
↓ apply 1NF
1NF — all values atomic
↓ remove partial deps
2NF — no partial dependencies
↓ remove transitive deps
3NF — no transitive dependencies
↓ every determinant is a superkey
BCNF — stronger than 3NF
↓ remove multi-valued deps
4NF → 5NF (next section)
1NF

First Normal Form

Rule: All attribute values must be atomic (indivisible). No multi-valued attributes, no repeating groups, no arrays in cells.
❌ Violates 1NF
Stu_IDPhone
1019876543, 8765432
Cell has multiple values
✅ 1NF
Stu_IDPhone
1019876543
1018765432
Separate row per value
Rule of thumb: If a cell contains a list/multiple values → NOT in 1NF
2NF

Second Normal Form

Rule: In 1NF + every non-prime attribute is fully functionally dependent on the ENTIRE primary key. Applies only when PK is composite.
Problem relation: ENROLLMENT(Student_ID, Course_ID, Grade, Student_Name, Course_Name)
PK = {Student_ID, Course_ID}
Grade → depends on both ✅
Student_Name → depends only on Student_ID ❌ (partial)
Course_Name → depends only on Course_ID ❌ (partial)
→ Decompose to 2NF:
STUDENT(Student_ID, Student_Name)
COURSE(Course_ID, Course_Name)
ENROLLMENT(Student_ID, Course_ID, Grade)  ← only Grade here
3NF

Third Normal Form

Rule: In 2NF + no transitive dependencies. For every FD X→Y: either (a) X is a superkey, OR (b) Y is a prime attribute.
Problem: STUDENT(Student_ID, Name, Dept_ID, Dept_Name, HOD_Name)
Student_ID → Dept_ID → Dept_Name (transitive!) ❌
→ Decompose to 3NF:
STUDENT(Student_ID, Name, Dept_ID)
DEPARTMENT(Dept_ID, Dept_Name, HOD_Name)
BCNF

Boyce-Codd Normal Form

Rule: For every non-trivial FD X→Y, X must be a superkey. Stronger than 3NF — eliminates ALL FD anomalies.
Problem: COURSE_TEACHER(Student_ID, Subject, Teacher)
Candidate keys: {Student_ID, Subject}, {Student_ID, Teacher}
Teacher → Subject ❌ (Teacher is not a superkey)
→ Decompose to BCNF:
TEACHER_SUBJECT(Teacher, Subject)
STUDENT_TEACHER(Student_ID, Teacher)
BCNF vs 3NF: 3NF allows Y to be a prime attribute as exception. BCNF is stricter — no exceptions. Every BCNF relation is in 3NF, but NOT vice versa.

Normal Forms — Quick Comparison

Normal FormCondition to satisfyEliminates
1NFAll values atomic; no repeating groups; each row uniqueMulti-valued cells, repeating groups
2NF1NF + no partial dependencies on composite PKPartial functional dependencies
3NF2NF + no transitive dependenciesTransitive functional dependencies
BCNFFor ALL X→Y: X is a superkeyAll FD-based anomalies
Exam tip: 2NF only matters when PK is composite. If PK is a single attribute, 1NF → 2NF automatically. BCNF is stricter than 3NF. Most production DBs target 3NF or BCNF.
06
Advanced NF

4NF and 5NF

Multi-valued & Join dependencies

Multi-Valued Dependency (MVD)

X →→ Y ("X multi-determines Y"): for a given X, there's a set of Y values independent of other attributes in the relation.
Example: EMPLOYEE_SKILLS(Employee_ID, Skill, Language)
An employee can have multiple skills AND multiple languages — independently of each other.
Employee_ID →→ Skill   AND   Employee_ID →→ Language
Problem: 3 skills × 2 languages = 6 rows (redundancy explosion). Inserting a new language requires adding N rows (one per skill).
4NF

Fourth Normal Form

Rule: In BCNF + no non-trivial multi-valued dependencies, unless the left side is a superkey.
EMPLOYEE_SKILLS(Employee_ID, Skill, Language) ← violates 4NF

→ Decompose:
EMPLOYEE_SKILL(Employee_ID, Skill)
EMPLOYEE_LANGUAGE(Employee_ID, Language)  ← 4NF ✅
Result: Adding a new language now requires only 1 row, not N rows.

Join Dependency (JD)

*{R1, R2…Rn} on R means R can be reconstructed exactly by joining its projections R1, R2…Rn. Every MVD is a special case of JD (with just 2 components).
5NF

Fifth Normal Form (PJNF)

Rule: In 4NF + every join dependency is implied by the candidate keys. (Project-Join Normal Form)
Example: SUPPLY(Supplier, Part, Project) — complex 3-way dependency.
Rule: if a supplier supplies a part AND that part is used in a project AND the supplier works on that project → supplier supplies that part for that project.
SUPPLIER_PART(Supplier, Part)
PART_PROJECT(Part, Project)
SUPPLIER_PROJECT(Supplier, Project)
← Original SUPPLY = join of these three ✅

All Normal Forms — Master Summary

NFPrerequisiteEliminatesWhen to apply
1NFNon-atomic values, repeating groupsAlways — minimum requirement
2NF1NFPartial FDs on composite PKWhen PK is composite
3NF2NFTransitive dependenciesMost production DBs stop here
BCNF3NFAll FD anomalies (stricter 3NF)When 3NF still has anomalies
4NFBCNFNon-trivial MVD redundancyMany-to-many independent attrs
5NF4NFJoin dependency anomaliesComplex 3-way+ relationships
Practical target: 3NF or BCNF for most real databases. 4NF/5NF for complex M:N relationships.
Exam tip: FD = one value determines another (X→Y). MVD = one value determines a SET of values independently (X→→Y). 4NF handles MVDs; 5NF handles JDs. MVD is a special case of JD.
FC
Study Mode

Flashcards

Tap card to flip

Quick Ref

Master Cheatsheet

Every Key Rule in One Table

TopicKey Rule / Fact
ER Model byPeter Chen, 1976
Relational Model byE.F. Codd, 1970
Entity vs Entity TypeEntity = specific object; Entity Type = category (rectangle)
Multi-valued attributeDouble oval — e.g. Phone_Numbers
Derived attributeDashed oval — e.g. Age from DOB
Key attributeUnderlined oval — uniquely identifies entity
Weak entity notationDouble rectangle + Double diamond
Partial key notationDashed underline
Total participationDouble line — every entity MUST participate
Cardinality 1:NOne in A → many in B (e.g. Dept has many Employees)
Cardinality M:NRequires junction table in relational schema
Degree of relation# of attributes (columns)
Cardinality of relation# of tuples (rows)
NULL ≠NULL ≠ 0, NULL ≠ '', any op with NULL = NULL
Superkey vs Candidate KeyCK = minimal superkey (no redundant attrs)
Entity IntegrityPK cannot be NULL
Referential IntegrityFK must match existing PK or be NULL
1NF ruleAll values atomic — no lists in cells
2NF ruleNo partial FDs on composite PK
3NF ruleNo transitive FDs
BCNF ruleFor every X→Y, X must be superkey (no exceptions)
4NF ruleNo non-trivial MVDs unless LHS is superkey
5NF ruleAll JDs implied by candidate keys
FD vs MVDFD: X→Y (one value). MVD: X→→Y (set of values independently)
Practical NF target3NF or BCNF for most databases