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 spreadsheetRecordA single row of a tableSchemaThe structure of a database, meaning which tables and columns existNormalizationSplitting up data so as little as possible is stored twiceQuerying data
SELECT * FROM table;Shows all columns and rows of a tableSELECT column FROM table;Shows only a specific columnWHERE conditionFilters the results by a conditionORDER BY columnSorts the result by a columnLIMIT 10Limits the result to a number of rowsChanging data
INSERT INTO table VALUES (...)Inserts a new rowUPDATE table SET column = valueChanges existing valuesDELETE FROM table WHERE ...Deletes rows matching the conditionCreating tables
CREATE TABLECreates a new table with its columnsPRIMARY KEYMarks the unique identifier of a rowFOREIGN KEYReferences the primary key of another tableALTER TABLEChanges a table's structure afterwardJoining tables
JOINConnects rows from two tables via a shared columnINNER JOINShows only rows that have a match in both tablesLEFT JOINShows all rows from the left table, even without a match on the rightWorth a look
Joining two tables
The foreign key in one table references the primary key of the other.
Customers
id (primary key)
name
email
joined via
customer_id →
customer_id →
Orders
id
customer_id (foreign key)
date