02 - Relational Databases & SQL
What is a Relational Database?
A relational database organizes data into tables (relations) with predefined schemas. Tables relate to each other through keys, enabling powerful queries across multiple tables.
The Relational Model
Plain text
┌─────────────────────────────────────────────────────────────┐
│ DATABASE │
├─────────────────────────────────────────────────────────────┤
│ │
│ ┌──────────────┐ ┌──────────────┐ │
│ │ USERS │ │ ORDERS │ │
│ ├──────────────┤ ├──────────────┤ │
│ │ id (PK) │◄────────│ user_id (FK) │ │
│ │ name │ 1:M │ id (PK) │ │
│ │ email │ │ total │ │
│ │ created_at │ │ status │ │
│ └──────────────┘ └──────────────┘ │
│ │ │
│ │ 1:1 │
│ ▼ │
│ ┌──────────────┐ │
│ │ USER_PROFILES│ │
│ ├──────────────┤ │
│ │ user_id (FK)│ │
│ │ bio │ │
│ │ avatar_url │ │
│ └──────────────┘ │
│ │
└─────────────────────────────────────────────────────────────┘
PK = Primary Key (unique identifier)
FK = Foreign Key (reference to another table)
1:M = One-to-Many relationship
1:1 = One-to-One relationship
M:N = Many-to-Many (requires junction table)