The Relational Model & SQL
The problem
Applications need to store structured data durably and query it flexibly — not just 'get this one record' but 'get every record matching these conditions, combined with related records from elsewhere' — without writing custom retrieval code for every possible question in advance.
Why now
Sets and logic already gave the vocabulary for describing collections and conditions precisely; the relational model is that vocabulary made literal — a table is a set of rows, and a SQL query is a logical proposition selecting a subset of it. This is why SQL reads like formal logic once you know what to listen for.
Mental model
A table is a set of rows, each row a tuple of values; a query is a proposition over that set — WHERE is a filter (set restriction by a predicate), JOIN is a combination of two sets by a matching condition, and the whole relational model is set theory and predicate logic wearing a database's clothes.
Requires
- Sets & LogicMathematical Thinking
A relational table is formally a set of tuples, and SQL's WHERE clause is a predicate exactly like the propositions sets-and-logic introduced — the relational model is applied set theory, not an analogy to it.
- Functions & RelationsMathematical Thinking
A table itself is a mathematical relation (a set of tuples over several domains); the 'relational' in relational database refers directly to this concept, not loosely to 'things being related.'
Unlocks
Used in
- PostgreSQL, MySQL, SQLite, and every relational database in production use
- ORMs (Object-Relational Mappers) that generate SQL from application code
- Data analysis and reporting, almost universally expressed as SQL queries
- Understanding query results as literal set operations (union, intersection, difference all have SQL equivalents)
Projects
- Design a small relational schema (e.g. books and authors) and write SELECT, INSERT, UPDATE, and DELETE queries against it
- Write the same data-retrieval question as both a SQL query and an equivalent set-theory statement, and confirm they say the same thing
Examples
- SELECT * FROM users WHERE age > 18 is a set restriction — keep only the tuples satisfying the predicate age > 18
- SELECT * FROM a UNION SELECT * FROM b is literally the set union of two relations
Resources
- PostgreSQL Tutorialdocs
- SQL — Khan Academycourse
Mastery checklist
- I can write SELECT queries with filtering, sorting, and basic joins
- I can explain a table as a set of tuples and a query as a predicate over that set
- I can perform basic create/read/update/delete operations in SQL
- I can translate a plain-English data question into a correct SQL query