Introduction to SQL
What databases are, why SQL exists, and how tables work
Skills taught: sql.database-concepts, sql.tables, sql.columns, sql.rows, sql.primary-key
What is a relational database?
A relational database stores data in tables. Each table has columns (defining what data is stored) and rows (actual records). Tables can reference each other via keys — that's the 'relational' part.
- Table
- A named grid of rows (records) and columns (fields). Like a spreadsheet tab, but with strict types and constraints.
- Primary Key
- A column (or combination) that uniquely identifies every row. Usually an auto-incrementing integer: id = 1, 2, 3, ...
- Foreign Key
- A column that stores the primary key of a row in another table. orders.user_id references users.id — linking each order to the user who placed it.
Our learning database
Throughout this SQL course, we'll use a simple e-commerce database with three tables. Every interactive playground in every lesson has these tables pre-loaded.
-- users: people who have accounts
users(id, name, email, city, joined_at)
-- products: items for sale
products(id, name, category, price, stock)
-- orders: purchases (links users to products)
orders(id, user_id, product_id, quantity, total, ordered_at)
Frequently Asked Questions
What is the difference between SQL and a database?
SQL is a language — it's like Python or JavaScript. A database is a program that stores data — like SQLite, PostgreSQL, or MySQL. You use SQL to communicate with any of these databases. The same SQL (mostly) works across all of them.
Which database should I use?
SQLite for learning, prototyping, and small apps (no setup needed — it's a single file). PostgreSQL for production web apps. MySQL/MariaDB for legacy stacks. This course teaches standard SQL that works everywhere, with notes on differences.