Purpose and content of

ER Diagrams (Chapter 2 – ER Diagram) Key Concepts

Entity:


A person, place, thing, or event you store data about (e.G., Student, Course).

Attribute:


A detail about an entity (e.G., StudentName, StudentID).

Identifier (Key):


Uniquely identifies each entity (StudentID).

Relationship:


How entities connect (e.G., Student registers for Course).

TypeMeaningExample
SimpleSingle valueName
CompositeCan be splitFullName → FirstName, LastName
MultivaluedHas several valuesSkills = {Java, SQL}
DerivedComputed from othersAge (from DOB)

0

Entity Types

Strong Entity:


Exists independently (e.G., Employee).

Weak Entity:


Depends on another entity (e.G., Dependent of Employee).

Relationships

TypeMeaningExample
UnaryEntity relates to itselfEmployee manages Employee
BinaryTwo entitiesStudent enrolls in Course
TernaryThree entitiesDoctor treats Patient using Drug

Cardinality

1:1 – One to One

1:N – One to Many

M:N – Many to Many
Defines how many instances connect and whether they must connect (mandatory or optional)

Enhanced ER Diagrams (EnhancedERD)


Supertypes & Subtypes

Supertype:


Big, general group (e.G., Employee).

Subtype:


Smaller, more specific group (e.G., Manager, Technician).

Inheritance:


Subtypes get all attributes of the supertype.

Generalization (Bottom-Up)


Combine smaller entities into one big group.
Car, Truck, Bike → Vehicle.

Specialization (Top-Down)


Split one big entity into smaller, specific ones.
Vehicle → Car, Truck, Motorcycle.

Constraints

TypeMeaningSymbol
Completeness
Do all supertype entities belong to a subtype?
Total (double line) / Partial (single line)

Disjointness

Can one supertype be in multiple subtypes?Disjoint (only one) / Overlap (can be several)

Subtype Discriminator

Attribute used to tell which subtype appliese.G., EmployeeType = “Hourly” or “Salaried”


Relational Model (Relational_Model(2))


Core Idea

A relational database stores data in tables (relations)
made of rows (tuples)
and columns (attributes).

Keys

Key TypePurpose
Primary Key (PK)
Uniquely identifies each row; can’t be NULL
Foreign Key (FK)
Connects tables; references a PK in another table

Candidate Key


Any possible key that could be the PK
Alternate Key
A candidate key not chosen as the PK
Composite Key
Combination of multiple columns to form a PK

Integrity Rules

RuleDescription
Domain Integrity
Values must be of the right type
Entity Integrity
PK can’t be NULL
Referential Integrity
FK must match a valid PK or be NULL

Nulls

Means unknown or not applicable.

Affects math and comparisons — any math with NULL = NULL.

ERD → Relational Model

Goal

Turn an ERD (diagram) into tables for a relational database.

7 Steps

StepProcessExample
1. Regular Entities
Each entity → Table; attributes → ColumnsSTUDENT(Name, ID, Major)

2. Weak Entities

New table with FK from parent + partial keyDEPENDENT(DepName, EmpID FK)

3. Binary Relationships

Add FK to “many” side (1:N) or create table (M:N)ORDER has FK for CUSTOMER
4. Associative Entities
New table with FKs; may have its own IDENROLLMENT(StudentID, CourseID, Grade)

5. Unary Relationships

FK within same tableEMPLOYEE(ManagerID FK)

6. Ternary Relationships

New table with all PKs as FKsPATIENT_TREATMENT(DoctorID, PatientID, DrugID)

7. Super/Subtype

Table for supertype + table for each subtypeEMPLOYEE, MANAGER, TECHNICIAN


Normalization

Purpose

Clean up data tables to remove redundancy and update problems (anomalies).

Common Anomalies

TypeProblem
Insertion
Can’t add data without other data
Deletion
Lose data you wanted to keep
Update
Must change the same data in multiple places

Goals

Reduce redundancy

Enforce data integrity

Make updates simple and safe

Normal Forms

FormRuleFixes
1NF
No repeating groups, one value per cellSplit multivalued attributes
2NF
No partial dependency (depends on full key)Split into smaller tables
3NF
No transitive dependency (non-key → non-key)Separate unrelated attributes
BCNF
Every determinant is a candidate keyStronger 3NF
4NF/5NF
Remove multivalued dependenciesRarely used in practice