Relational Database Model

Overview

The Relational Database Model, introduced by Dr. E.F. Codd in 1970, is the foundation of modern database systems. It organizes data into tables (relations) consisting of rows (tuples) and columns (attributes), establishing relationships between tables through keys.

The relational model provides a mathematical foundation for database management and ensures data integrity through constraints and relationships.

Core Concepts

1. Relation (Table)

A relation is a two-dimensional table that contains data. It's the fundamental structure in the relational model.

Example: Students Relation (Table)
┌─────────────┬──────────────┬──────────────┐
│ StudentID   │ StudentName  │ Department   │
├─────────────┼──────────────┼──────────────┤
│ 101         │ John Smith   │ Computer Sci │
│ 102         │ Jane Doe     │ Mathematics  │
│ 103         │ Bob Johnson  │ Computer Sci │
└─────────────┴──────────────┴──────────────┘

2. Tuple (Row)

A tuple is a single row in a relation, representing one instance of an entity. Each tuple contains values for all attributes.

3. Attribute (Column)

An attribute is a column in a relation, representing a property of the entity. Each attribute has a domain (set of valid values).

4. Domain

A domain is the set of all possible values that an attribute can take. For example, the domain of "Age" might be all positive integers.

5. Degree and Cardinality

Properties of Relations

Relations in the relational model have specific properties:

Keys

Keys are crucial for establishing relationships and ensuring data integrity:

Primary Key

A primary key uniquely identifies each tuple in a relation. It must be unique and cannot be NULL.

Primary Key Example
Students Table:
┌─────────────┬──────────────┬──────────────┐
│ StudentID   │ StudentName  │ Department   │
│ (Primary    │              │              │
│  Key)       │              │              │
├─────────────┼──────────────┼──────────────┤
│ 101         │ John Smith   │ Computer Sci │
│ 102         │ Jane Doe     │ Mathematics  │
└─────────────┴──────────────┴──────────────┘

Foreign Key

A foreign key is an attribute (or set of attributes) in one relation that references the primary key of another relation, establishing relationships between tables.

Foreign Key Example
Students Table (Primary Key: StudentID)
┌─────────────┬──────────────┐
│ StudentID   │ StudentName  │
├─────────────┼──────────────┤
│ 101         │ John Smith   │
│ 102         │ Jane Doe     │
└─────────────┴──────────────┘

Enrollments Table (Foreign Key: StudentID)
┌─────────────┬──────────────┬──────────────┐
│ EnrollmentID│ StudentID    │ CourseID     │
│             │ (Foreign Key)│ (Foreign Key)│
├─────────────┼──────────────┼──────────────┤
│ 1           │ 101          │ CS101        │
│ 2           │ 102          │ MATH201      │
└─────────────┴──────────────┴──────────────┘

Candidate Key

A candidate key is any attribute or combination of attributes that can uniquely identify a tuple. One candidate key is chosen as the primary key.

Superkey

A superkey is any set of attributes that uniquely identifies tuples. It may contain more attributes than necessary.

Integrity Rules

1. Entity Integrity

No attribute that is part of the primary key can be NULL. This ensures every tuple can be uniquely identified.

2. Referential Integrity

A foreign key value must either match a primary key value in the referenced relation or be NULL. This ensures relationships between tables are valid.

Referential Integrity Example
Valid:
Enrollments.StudentID = 101  → Must exist in Students.StudentID
Enrollments.StudentID = NULL → Also allowed

Invalid:
Enrollments.StudentID = 999  → Does NOT exist in Students.StudentID
                              → Violates referential integrity!

Advantages of Relational Model

Relational Algebra

Relational algebra is the theoretical foundation of SQL operations. Core operations include:

Mapping ER Model to Relational Model

When converting an ER diagram to relational tables:

Conversion Rules
1. Entity → Table
   - Entity name becomes table name
   - Attributes become columns
   - Primary key identified

2. Relationship → Foreign Key
   - 1:1 relationship: Foreign key in either table
   - 1:M relationship: Foreign key in "many" table
   - M:M relationship: Create junction table

3. Attributes → Columns
   - Simple attributes → Single column
   - Composite attributes → Multiple columns
   - Multivalued attributes → Separate table

Relational Database Management System (RDBMS)

An RDBMS is software that manages relational databases. Popular RDBMS include:

Next Steps

Learn about representing relationships visually with ERD & Crow's Foot Notation, or explore database design principles in Normalization.