SQL Tutorial · SQL Basics · Lesson 2 of 36
The Sample Database
The tables used throughout this tutorial: customers, products, orders and employees.
The tables
| Table | What it holds |
|---|---|
customers |
customer_id, name, email, city, country, signup_date |
categories |
category_id, name |
products |
product_id, name, category_id, price, stock |
orders |
order_id, customer_id, order_date, status |
order_items |
order_id, product_id, quantity, unit_price |
employees |
employee_id, name, title, department, manager_id, salary, hire_date |
How the tables relate
customers 1 ──< orders 1 ──< order_items >── 1 products >── 1 categories
employees.manager_id ──> employees.employee_id (an employee's manager)
- One customer has many orders; each order has many order items.
- Each order item points to one product; each product belongs to one category (one product has none).
- Employees reference their manager in the same table.
Dates are stored as ISO text ('2026-03-17'), which sorts and compares correctly.
Look around
SELECT name FROM sqlite_master WHERE type = 'table' ORDER BY name;
SELECT * FROM categories;
Output
name categories customers employees order_items orders products category_id | name 1 | Books 2 | Electronics 3 | Home 4 | Toys
sqlite_master is SQLite's catalogue of tables. In PostgreSQL and MySQL you'd query information_schema.tables instead.
Test yourself
Which column links an order to the customer who placed it?
orders.order_idorders.customer_idcustomers.emailorder_items.product_id
Show answer
Answer: orders.customer_id