Lesson 1: Tables and keys
A relational database stores related data in tables. Each row represents one record and each column describes one attribute. A primary key uniquely identifies a row.
CREATE TABLE courses (
id INTEGER PRIMARY KEY,
title TEXT NOT NULL
);
CREATE TABLE lessons (
id INTEGER PRIMARY KEY,
course_id INTEGER NOT NULL REFERENCES courses(id),
title TEXT NOT NULL
);The course_id foreign key connects each lesson to a course. This avoids repeating course details on each lesson row and helps keep data consistent.
Practice
Design tables for authors and books. Choose a primary key for each, then add a foreign key that connects every book to its author.