Database Management Systems

Module 1

Database Fundamentals & ER Model

Introduction to DBMS, ER diagrams, relational model, and schema design

Theory

Database Fundamentals & ER Model

Databases are organized collections of data that allow efficient storage, retrieval, and management of information. This module covers foundational concepts essential for CUET PG and data engineering roles.

What You'll Learn

#TopicSkill
1Database ConceptsDBMS vs File System, data independence
2ER ModelEntities, attributes, relationships
3EER ModelGeneralization, specialization, aggregation
4Relational ModelTables, keys, constraints
5Schema DesignER to Relational mapping

1. Introduction to Databases

What is a Database? A database is an organized collection of structured data stored electronically. A Database Management System (DBMS) is software that manages this data.

DBMS vs File System:

AspectFile SystemDBMS
Data RedundancyHighMinimal (controlled)
Data IntegrityManual enforcementAutomatic constraints
ConcurrencyNo supportBuilt-in support
SecurityOS-levelFine-grained access control
Data IndependenceNoneLogical & Physical
RecoveryManual backupsAutomatic crash recovery

Three-Schema Architecture:

text
External Level (View Schema)
    ↓ Logical Data Independence
Conceptual Level (Logical Schema)
    ↓ Physical Data Independence  
Internal Level (Physical Schema)
  • External Schema: User views, customized for different users
  • Conceptual Schema: Logical structure of entire database
  • Internal Schema: Physical storage structure

Data Independence:

  • Logical: Changes to conceptual schema don't affect external views
  • Physical: Changes to physical storage don't affect logical schema

2. Entity-Relationship (ER) Model

ER Model is a high-level conceptual data model used to describe the database structure graphically.

Core Components:

text
┌─────────────────────────────────────────────────┐
│               ER DIAGRAM SYMBOLS                │
├─────────────────────────────────────────────────┤
│  ┌───────┐                                      │
│  │       │  Rectangle = Entity                  │
│  └───────┘                                      │
│                                                 │
│     ○      Ellipse = Attribute                  │
│                                                 │
│     ◇      Diamond = Relationship               │
│                                                 │
│    ___     Underline = Primary Key              │
│                                                 │
│    (-)     Dashed Ellipse = Derived Attribute   │
│                                                 │
│   {  }     Double Ellipse = Multivalued Attr    │
└─────────────────────────────────────────────────┘

Attribute Types:

TypeDescriptionExample
SimpleAtomic, cannot be dividedFirst Name
CompositeCan be dividedFull Name (First + Last)
Single-valuedOne value per entityDate of Birth
Multi-valuedMultiple valuesPhone Numbers
DerivedCalculated from other attributesAge (from DOB)
KeyUniquely identifies entityEmployee ID

Example: University Database ER

python
# Entity: STUDENT
# Attributes: student_id (PK), name, email, dob, age (derived)

# Entity: COURSE  
# Attributes: course_id (PK), course_name, credits

# Relationship: ENROLLS
# Student <--(enrolls)--> Course
# Cardinality: Many-to-Many (M:N)
# A student can enroll in many courses
# A course can have many students

# Relationship Attributes:
# enrollment_date, grade

Relationship Types:

text
1:1 (One-to-One)
┌───────┐      ┌───────┐
│ Person │──────│ Passport│
└───────┘      └───────┘
One person has exactly one passport

1:N (One-to-Many)
┌───────┐      ┌───────┐
│ Dept  │──────<│ Employee│
└───────┘      └───────┘
One department has many employees

M:N (Many-to-Many)
┌───────┐>─────<┌───────┐
│Student│      │ Course │
└───────┘      └───────┘
Many students enroll in many courses

Participation Constraints:

  • Total (Mandatory): Every entity must participate (double line)
  • Partial (Optional): Participation is optional (single line)

3. Enhanced ER (EER) Model

Generalization: Bottom-up approach - combine similar entities into a higher-level entity.

text
        ┌─────────┐
        │ VEHICLE │  ← Generalized Entity
        └────┬────┘
             │
    ┌────────┼────────┐
    ↓        ↓        ↓
┌─────┐  ┌─────┐  ┌─────┐
│ Car │  │ Truck│  │ Bike │
└─────┘  └─────┘  └─────┘

Specialization: Top-down approach - create specialized sub-entities from general entity.

text
        ┌──────────┐
        │ EMPLOYEE │  ← Superclass
        └────┬─────┘
             │ is-a
    ┌────────┼────────┐
    ↓        ↓        ↓
┌───────┐ ┌───────┐ ┌───────┐
│ Manager│ │Engineer│ │ Intern │
└───────┘ └───────┘ └───────┘
            ↑ Subclasses

Aggregation: Treating a relationship as a higher-level entity.

python
# Example: Project Management
# Relationship "Works_On" between Employee and Project
# This relationship itself participates in "Manages" relationship

# Employee ---(works_on)--- Project
#               |
#               | (aggregation)
#               ↓
#           [Monitors]
#               ↑
#           Manager

4. Relational Model

Core Concepts:

TermDefinition
RelationA table with rows and columns
TupleA row (record) in a table
AttributeA column (field) in a table
DomainSet of allowed values for an attribute
DegreeNumber of attributes (columns)
CardinalityNumber of tuples (rows)
SchemaStructure definition (column names & types)
InstanceActual data at a given time

Keys in Relational Model:

sql
-- STUDENT Table Example
CREATE TABLE Student (
    student_id INT PRIMARY KEY,      -- Primary Key
    email VARCHAR(100) UNIQUE,       -- Candidate Key
    name VARCHAR(50) NOT NULL,
    dept_id INT,
    FOREIGN KEY (dept_id) REFERENCES Department(dept_id)
);

-- Key Types:
-- Super Key: Any set of attributes that uniquely identifies tuples
--   {student_id}, {student_id, name}, {email}, {email, name}

-- Candidate Key: Minimal super key (no redundant attributes)
--   {student_id}, {email}

-- Primary Key: Chosen candidate key for identification
--   student_id

-- Foreign Key: References primary key of another table
--   dept_id references Department(dept_id)

-- Alternate Key: Candidate keys not chosen as primary key
--   email

Integrity Constraints:

ConstraintDescription
DomainValues must be from attribute's domain
KeyPrimary key must be unique and NOT NULL
Entity IntegrityNo part of primary key can be NULL
Referential IntegrityForeign key must reference valid primary key or be NULL

5. ER to Relational Mapping

Step-by-Step Mapping Algorithm:

python
# Step 1: Map Regular Entities
# Each entity → Table
# Simple attributes → Columns
# Composite attributes → Component attributes as columns
# Multivalued attributes → Separate table with FK

# Step 2: Map Weak Entities
# Include partial key + owner's PK as composite primary key

# Step 3: Map Binary 1:1 Relationships
# Add FK to either side (preferably total participation side)
# Or create separate relationship table

# Step 4: Map Binary 1:N Relationships
# Add FK to "many" side (N-side entity)
# Relationship attributes go with FK

# Step 5: Map Binary M:N Relationships
# Create new relationship table
# Include PKs of both entities as composite PK
# Add relationship attributes to this table

# Step 6: Map Multivalued Attributes
# Separate table with attribute + foreign key to owner

# EXAMPLE:
# Student (M) --- enrolls --- (N) Course
# Creates: Enrollment(student_id, course_id, grade, date)

Mapping Example:

sql
-- Original ER: Student --enrolls-- Course (M:N)

-- Resulting Tables:
CREATE TABLE Student (
    student_id INT PRIMARY KEY,
    name VARCHAR(50),
    email VARCHAR(100)
);

CREATE TABLE Course (
    course_id INT PRIMARY KEY,
    course_name VARCHAR(100),
    credits INT
);

-- Relationship becomes a table
CREATE TABLE Enrollment (
    student_id INT,
    course_id INT,
    enrollment_date DATE,
    grade CHAR(1),
    PRIMARY KEY (student_id, course_id),
    FOREIGN KEY (student_id) REFERENCES Student(student_id),
    FOREIGN KEY (course_id) REFERENCES Course(course_id)
);

TL;DR - Quick Reference

ConceptKey Point
DBMS AdvantageData independence, integrity, concurrency, security
Three SchemaExternal (views) → Conceptual (logical) → Internal (physical)
ER EntityRectangle, has attributes
ER RelationshipDiamond, connects entities with cardinality
EER GeneralizationCombine similar entities (bottom-up)
EER SpecializationCreate sub-entities (top-down)
Candidate KeyMinimal set of attributes uniquely identifying tuples
Referential IntegrityFK must match valid PK or be NULL
1:N MappingFK goes to N-side entity
M:N MappingCreate separate relationship table

Resources

Practice

Test your understanding

📝

Practice Quiz

10 questions · 90s per question

Each question has a 90-second time limit. Unanswered questions will be auto-submitted when time runs out.