πΎ
EPISODE 01
Relational vs NoSQL Β· schema Β· primary key Β· normalization
Database Concepts
Understand why we need databases, the difference between relational and NoSQL, and core concepts: tables, rows, columns, primary keys, and normalization.
databaseSQLNoSQLschemaPK
Duration
β± About 1.5 hours
Level
π Beginner
Prerequisite
π― Stage 3 entry
OUTCOME
Pick the right database type and design a clean schema
What you'll learn
- 1Explain why JSON files fail at scale
- 2Distinguish relational (SQL) from NoSQL databases
- 3Design tables with proper primary keys
- 4Apply basic normalization (1NF, 2NF, 3NF) β at a high level
1. Why a Database?
- Concurrency β many writers without losing data
- Querying β fast lookups, joins, aggregations
- Integrity β types, constraints, transactions
- Durability β survive crashes and power loss
2. Relational vs NoSQL
| Aspect | Relational (SQL) | NoSQL (e.g. MongoDB) |
|---|---|---|
| Data model | Tables with rows and columns | Documents (JSON-like) |
| Schema | Strict, defined upfront | Flexible per document |
| Joins | Native, fast | Manual or denormalized |
| Use cases | Most business apps | Logs, content stores, rapid prototyping |
| Examples | SQLite, PostgreSQL, MySQL | MongoDB, DynamoDB, Firestore |
3. Tables, Rows, Columns
text
users table
ββββββ¬βββββββββββ¬ββββββββββββββββββββββββ
β id β name β email β
ββββββΌβββββββββββΌββββββββββββββββββββββββ€
β 1 β Alice β alice@example.com β
β 2 β Bob β bob@example.com β
ββββββ΄βββββββββββ΄ββββββββββββββββββββββββ- Each row = one entity (a user, a task, etc.)
- Each column = one attribute with a type
- Primary key = a unique identifier (often id)
- Foreign key = a column that references another table's PK
4. Normalization (Quick Take)
- 1NF β atomic values (no "comma, separated, lists" in a cell)
- 2NF β every non-key column depends on the whole PK
- 3NF β no transitive dependencies (no derived columns)
- Rule of thumb: model 1-to-many and many-to-many with separate tables joined by FK
π‘
Over-normalization is also a problem. Start normalized; denormalize only when you have a real performance need.
Example code / lecture materials
All lecture materials and example code are openly available on GitHub.
View on GitHub β