SQL and Databases Basics

The basic commands to query data from a database, change it, and sensibly link tables together.

Last updated: September 1, 2026

Terms

SQL is a language for querying, changing and managing data in a database. A database stores data similarly to several linked spreadsheets.

TableStores data in rows and columns, like a spreadsheet
RecordA single row of a table
SchemaThe structure of a database, meaning which tables and columns exist
NormalizationSplitting up data so as little as possible is stored twice

Querying data

SELECT * FROM table;Shows all columns and rows of a table
SELECT column FROM table;Shows only a specific column
WHERE conditionFilters the results by a condition
ORDER BY columnSorts the result by a column
LIMIT 10Limits the result to a number of rows

Changing data

INSERT INTO table VALUES (...)Inserts a new row
UPDATE table SET column = valueChanges existing values
DELETE FROM table WHERE ...Deletes rows matching the condition

Creating tables

CREATE TABLECreates a new table with its columns
PRIMARY KEYMarks the unique identifier of a row
FOREIGN KEYReferences the primary key of another table
ALTER TABLEChanges a table's structure afterward

Joining tables

JOINConnects rows from two tables via a shared column
INNER JOINShows only rows that have a match in both tables
LEFT JOINShows all rows from the left table, even without a match on the right
Worth a look

Joining two tables

The foreign key in one table references the primary key of the other.