█
LastWrite
  • > Curriculum
  • > Pricing
  • > For Educators
  • > About
  • > Contact
Log InGet Started

Questions, concerns, bug reports, or suggestions? We read every message, write to us at [email protected].

More ways to reach us →
LastWrite

Structured computer science lessons for aspiring developers and security professionals.

[email protected]

(201) 785-7951

Mon–Fri, 9 AM–5 PM EST

Learn

  • Curriculum
  • Pricing

Company

  • About
  • For Educators & Schools
  • Contact Us

Legal

  • Terms of Service
  • Privacy Policy
© 2026 LastWrite. All rights reserved.
Curriculum/Programming Languages/SQL/Relational Database Basics
25 minBeginner

Relational Database Basics

After this lesson, you will be able to: Explain what a relational database is and how tables, rows, columns, primary keys, and foreign keys work together.

SQL is the most-used data language on earth. Every backend dev needs it, not just for data work. PostgreSQL is what LastWrite (and most modern startups) use, and what this subtrack uses for all hands-on exercises.

This is a free introductory lesson. No purchase required.

Why SQL still matters in 2026

SQL has been the dominant query language since 1980 and still is. Every backend engineer interacts with it: REST APIs hit relational DBs, ETL pipelines pull from warehouses, analysts run reports. Knowing SQL well separates juniors who 'use the ORM' from engineers who debug slow queries.

Tables, rows, columns

Table = a spreadsheet. Rows = records. Columns = fields. Each column has a type (integer, text, date, boolean, etc.), enforced. Each table has a PRIMARY KEY, a column (or combo) that uniquely identifies each row. Tables relate via FOREIGN KEYS, a column whose value matches another table's primary key.

A two-table example (Postgres)

Users + their posts.

sql
CREATE TABLE users (
id SERIAL PRIMARY KEY, -- auto-incrementing int
email TEXT NOT NULL UNIQUE,
name TEXT NOT NULL,
created_at TIMESTAMPTZ DEFAULT NOW()
);
CREATE TABLE posts (
id SERIAL PRIMARY KEY,
user_id INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE,
title TEXT NOT NULL,
body TEXT NOT NULL,
published BOOLEAN DEFAULT FALSE,
created_at TIMESTAMPTZ DEFAULT NOW()
);
INSERT INTO users (email, name) VALUES ('[email protected]', 'Alex');
INSERT INTO posts (user_id, title, body, published)
VALUES (1, 'Hello SQL', 'My first post.', TRUE);

💡 Local Postgres setup

Mac: `brew install postgresql@16 && brew services start postgresql@16` Linux: `sudo apt install postgresql`, then `sudo -u postgres psql` Windows: download from postgresql.org or use Docker (`docker run --name pg -e POSTGRES_PASSWORD=pw -p 5432:5432 -d postgres:16`). Connect with `psql` CLI or DBeaver / TablePlus / pgAdmin GUI. Quick alternative: Neon (free Postgres cloud tier) at neon.tech.

Common mistakes only experienced SQL devs catch

Using SQLite or MySQL syntax with Postgres (or vice versa, they differ subtly). Treating SQL as 'just talk to ORM', debugging slow queries needs real SQL fluency. Missing NOT NULL constraints on required columns (NULL bugs are forever). Picking VARCHAR over TEXT in Postgres (no performance difference; TEXT is cleaner).

Back to SQL
Basic SQL: SELECT, INSERT, UPDATE, DELETE→