← Back to the Build Your Homepage series
πŸ’Ύ
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

AspectRelational (SQL)NoSQL (e.g. MongoDB)
Data modelTables with rows and columnsDocuments (JSON-like)
SchemaStrict, defined upfrontFlexible per document
JoinsNative, fastManual or denormalized
Use casesMost business appsLogs, content stores, rapid prototyping
ExamplesSQLite, PostgreSQL, MySQLMongoDB, 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 β†—