Skip to content

Setup ​

Just enough tooling to run SQL locally - no Docker, no cloud console, no drama.

What you need ​

  • SQLite - the database engine (ships as the sqlite3 CLI on most systems)
  • A text editor (you already have one)
  • Optional: DB Browser for SQLite if you like clicking around

Think of SQLite as "a database that lives in one file". No server process. You open the file, run SQL, close it. Perfect for learning.

Install sqlite3 ​

Linux ​

bash
# Debian / Ubuntu
sudo apt install sqlite3

# Fedora
sudo dnf install sqlite

macOS ​

bash
brew install sqlite

(macOS often has a system sqlite3 already - brew gives you a newer one.)

Windows ​

Install from the SQLite download page, or use WSL and follow the Linux bits.

Check it:

bash
sqlite3 --version

Your first database ​

bash
mkdir -p ~/sql-playground
cd ~/sql-playground
sqlite3 hello.db

You're now inside the SQLite prompt (starts with sqlite>). Try:

sql
CREATE TABLE greetings (
  id INTEGER PRIMARY KEY,
  message TEXT NOT NULL
);

INSERT INTO greetings (message) VALUES ('hello from sql');

SELECT * FROM greetings;

Exit with .quit.

Comments for the code above:

  • hello.db is just a file on disk - that's the whole database
  • CREATE TABLE defines the shape (we'll go deep later)
  • INSERT adds a row; SELECT reads rows back

Running SQL from files ​

You don't have to type everything interactively. Later chapters point at examples/crm/*.sql:

bash
sqlite3 crm.db < schema.sql
sqlite3 crm.db < seed.sql

Or from inside the prompt:

sql
.read schema.sql

Handy CLI dots ​

CommandWhat it does
.tableslist tables
.schema contactsshow CREATE for a table
.mode columnprettier output
.headers onshow column names
.quitleave

I usually turn headers on once and forget about it:

sql
.headers on
.mode column

Postgres / MySQL note ​

If your day job uses Postgres or MySQL - good. The SQL we'll write is mostly portable. I'll call out the few spots where SQLite is weird (types, AUTOINCREMENT, etc.).

Next: Mental model - tables as collections of objects.

Notes-style SQL tutorial for front-end folks