🗄️ The Relational Model

Foundation of Modern Database Systems: Relations, Constraints, and Operations

📚 Chapter 4
🎯 CS 340
👩‍🎓 Shoug Alomran
⏱️ Comprehensive Summary

📑 Table of Contents

📜

Introduction & History

The Evolution of the Relational Model

🎯 The Relational Revolution

Introduced by Edgar Codd in 1970, the relational model revolutionized database management systems. It replaced complex network and hierarchical models with a simple, elegant table-based approach.

Why the Relational Model Won

❌ Older Models

  • Complex navigation
  • Required extensive application code
  • Difficult to query
  • Tight coupling with storage

✅ Relational Model

  • Simple table-based structure
  • Declarative queries (SQL)
  • Data independence
  • Easy to understand and use
1

Simplicity

The main abstract element is a table - easy to understand and work with

2

Physical Data Independence

Modify physical schema (storage) without affecting logical schema (structure)

3

Logical Data Independence

Modify conceptual schema without changing applications through views

🏆 Market Dominance

Today, the relational model is the most widely used model in the world. Competitors like NoSQL and XML databases have not achieved the same level of popularity or adoption.

📊

Basic Relational Model Concepts

Understanding Relations, Tuples, and Attributes

Formal Terminology vs Informal Terms

Informal Terms Formal Terms Description
Table Relation A set of rows and columns representing entities
Column Header Attribute A property or field in a relation
All Possible Column Values Domain Set of allowable values for an attribute
Row Tuple A single record in a relation
Table Definition Schema of Relation Structure definition with attributes and types
Populated Table State/Instance of Relation Actual data at a specific moment
📘 Relational Model Components

A Relational Database consists of:

  • Relations: A set of tables, each with two parts:
    • Schema: Name and structure (e.g., Employee(ID: string, Name: string, DOB: date))
    • Instance: Current data - rows (tuples) and columns
  • Database Schema: Collection of all relation schemas
  • Database Instance: Collection of all relation instances

Key Metrics

Degree (Arity)

Number of columns (attributes) in a relation

STUDENT(ID, Name, Major) has degree = 3

Cardinality

Number of rows (tuples) in a relation

If STUDENT has 500 students, cardinality = 500

💡 Example Relation

STUDENT Relation Schema:

STUDENT(Student_number: String, Name: String, Class: Integer, Major: String)

Sample Instance:

Student_number Name Class Major
17 Ahmad Ali 1 CS
8 Sara Khalid 2 SE

Characteristics of Relations

Properties that Define Relational Tables

1

Atomic Values (1NF)

All values are considered atomic (indivisible). No composite or multivalued attributes permitted. This is known as First Normal Form.

2

Domain Constraint

Each value in a tuple must be from the domain of its attribute, or it can be NULL if allowed.

3

Unordered Tuples

Tuples are not ordered in a relation, even if they appear ordered in the tabular form.

4

Ordered Attributes

Attributes and their values within tuples are considered to be ordered (though alternative definitions exist).

🔤 Self-Describing Representation

An alternative representation doesn't require attribute ordering and includes both name and value:

t = { <name, "Ahmad">, <SSN, 123456789> }

This is called a self-describing representation.

🌐 NULL Values

A special NULL value is used to represent values that are:

  • Unknown: The value exists but is not known
  • Unavailable: The value is not currently available
  • Inapplicable: The attribute doesn't apply to this tuple
🔐

Relational Model Constraints

Rules That Ensure Data Integrity

📋 What Are Constraints?

Constraints are conditions that must hold on all valid relation states. They ensure data accuracy, consistency, and integrity.

Types of Schema-Based Constraints

🔑

1. Key Constraints

Uniqueness constraint: No two tuples can have the same value for key attributes.

  • Superkey: Set of attributes that uniquely identifies tuples
  • Candidate Key: Minimal superkey (no redundant attributes)
  • Primary Key: Chosen candidate key (underlined in schema)
CAR(SerialNo, Make, Model, Year)

SerialNo is the primary key

2. Entity Integrity

Primary key cannot be NULL: PK attributes cannot have null values in any tuple.

t[PK] ≠ null for any tuple t in r(R)

Why? Primary key values identify individual tuples. Without a value, the tuple cannot be uniquely identified.

🔗

3. Referential Integrity

Foreign key constraint: Maintains consistency between related relations.

A tuple in referencing relation R1 has foreign key (FK) that references primary key (PK) in referenced relation R2.

FK value must be:

  • A value of an existing PK in R2, OR
  • NULL (if FK is not part of R1's primary key)
📦

4. Domain Constraints

Type constraint: Every value must be from the attribute's domain.

If Age domain is Integer(0-120), then:

  • ✅ Age = 25 (valid)
  • ❌ Age = "twenty-five" (invalid - wrong type)
  • ❌ Age = 150 (invalid - out of range)
🚫

5. NULL Constraints

Specifies whether NULL values are permitted for specific attributes.

If every STUDENT must have a valid Name:

Name NOT NULL
💡 Referential Integrity Example

Scenario: EMPLOYEE references DEPARTMENT

EMPLOYEE(SSN, Name, Salary, D_num) DEPARTMENT(Dnumber, Dname) Foreign Key: D_num in EMPLOYEE references Dnumber in DEPARTMENT

Every employee's D_num must match an existing Dnumber in DEPARTMENT (or be NULL if allowed).

🎨 Displaying Referential Integrity

In relational database schema diagrams:

  • Relations shown as rows of attribute names
  • Primary key attributes underlined
  • Foreign key constraints shown as directed arrows from FK to referenced relation
⚙️

Update Operations on Relations

Modifying Database State

🔄 Three Basic Operations

Database state changes through three basic operations:

INSERT

Add a new tuple to a relation

DELETE

Remove an existing tuple from a relation

✏️

MODIFY (UPDATE)

Change attribute values of an existing tuple

⚠️ Critical Rules
  • Integrity constraints must not be violated by update operations
  • Several update operations may need to be grouped together
  • Updates may propagate to cause other updates automatically to maintain integrity
🔄 State Transitions

Each update operation creates a new database state. The relational database state is the union of all individual relation states at that moment.

⚠️

Dealing with Constraint Violations

How Each Operation Can Violate Constraints

INSERT Operation Violations

📦

Domain Constraint

Violated if an attribute value is not of the specified domain

❌ INSERT STUDENT(123, "Ahmad", "junior", "CS")

If Class should be Integer, "junior" violates domain constraint

🔑

Key Constraint

Violated if the key value already exists

❌ INSERT STUDENT(123, "Sara", 2, "SE")

If Student_number 123 already exists, violates uniqueness

🔗

Referential Integrity

Violated if FK references non-existent PK

❌ INSERT EMPLOYEE(..., D_num=99)

If Department 99 doesn't exist, violates referential integrity

Entity Integrity

Violated if PK value is NULL

❌ INSERT STUDENT(NULL, "Omar", 1, "IT")

Primary key cannot be NULL

DELETE Operation Violations

🗑️ Referential Integrity Risk

DELETE may violate referential integrity if the PK value being deleted is referenced by FKs in other tuples.

🛠️ Remediation Options

When deletion would violate referential integrity:

  • RESTRICT: Reject the deletion
  • CASCADE: Delete referencing tuples as well (propagate deletion)
  • SET NULL: Set foreign key values to NULL in referencing tuples

One of these options must be specified during database design for each FK constraint.

💡 DELETE Examples
DELETE EMPLOYEE WHERE SSN = '333445555'

If this employee is referenced by:

  • Other EMPLOYEE tuples (as supervisor)
  • DEPARTMENT tuples (as manager)
  • WORKS_ON tuples
  • DEPENDENT tuples

This deletion is unacceptable without CASCADE or other handling.

UPDATE (MODIFY) Operation Violations

✏️ UPDATE Constraint Checks

Modifying a tuple can violate constraints similar to INSERT and DELETE:

  • Changing PK → may violate key constraint or cause referential integrity issues
  • Changing FK → may violate referential integrity
  • Changing any attribute → may violate domain constraints
🔄 Cascading Updates

Similar options exist for UPDATE operations:

  • RESTRICT: Reject the update
  • CASCADE: Propagate changes to referencing tuples
  • SET NULL: Set affected FKs to NULL

Chapter Summary

Key Takeaways from the Relational Model

📊 Core Structure

Relations (tables) with tuples (rows) and attributes (columns) form the foundation of modern databases

✨ Simplicity

Table-based abstraction is easy to understand, making relational databases accessible and widely adopted

🔐 Integrity

Four main constraints (domain, key, entity, referential) ensure data remains accurate and consistent

⚙️ Operations

INSERT, DELETE, UPDATE modify database state while respecting integrity constraints

🔗 Relationships

Foreign keys establish relationships between tables, maintaining referential integrity

🎯 Independence

Physical and logical data independence separate storage from structure and structure from applications

🎓 Next Steps

With the relational model foundations established, we can now:

  • Learn SQL for querying and manipulating relational databases
  • Understand normalization for optimal database design
  • Explore transaction management and concurrency control
  • Study query optimization and indexing strategies