SQL databases
Tables, keys and queries: how applications store data reliably in a relational database.
Why it matters
Almost every application keeps its important data in a SQL database. A good table design and a few correct queries prevent slow pages, duplicated data and lost updates.
Where it fits
What you will learn
- Create a table with a primary key and the right column types.
- Insert, select, filter and sort rows.
- Explain what a transaction guarantees.
Before you start
- HTTP and APIs✓ Learned
Tables, rows and keys
A table is a list of rows with the same columns. A primary key identifies each row; a foreign key points to a row in another table. The database enforces these rules, so bad data cannot get in.
CREATE TABLE users (
id INTEGER PRIMARY KEY,
email TEXT NOT NULL UNIQUE
);
INSERT INTO users (email) VALUES ('ana@example.com');
SELECT id, email FROM users ORDER BY email;
Transactions
A transaction groups statements so that they all succeed or none do — moving money between two accounts must never apply only half. Use them whenever one action changes several rows.
Watch out: Build queries with parameters (placeholders), never by joining user input into the SQL string. That is how SQL injection happens.
Install and set up
- PostgreSQL downloads ↗ Installers and packages for every operating system.
Official documentation and references
Documentation
- SQLite documentation ↗ Official · SQLite — The small file-based database Zerethon IDE runs SQL examples with.
Guides
- PostgreSQL tutorial ↗ Official · PostgreSQL
Practise in Zerethon IDE
- Code Help: SQL — CREATE TABLE and INSERT Copyable examples with their output.
- Code Help: SQL — Transactions
- Algorithm sample: SQL Basics · read the code, then use Open in IDE on its page A runnable SQL sample you can open in the IDE.
Learn next
- Git basics ›✓ Learned
Related topics
- Schema migrations✓ Learned
- Backups and recovery✓ Learned
- HTTP and APIs✓ Learned
Done with this topic?
Reviewed 2026-10-23. Links go to the official documentation unless marked otherwise.