databases/why-databases-split-your-data-into-two-tables-and-link-them-by-id.md
Why databases split your data into two tables (and link them by id)
A database table looks like a spreadsheet: columns for each kind of information, one row per thing. But it comes with rules. Every column has a data type, and every row gets a primary key, an id that is never empty and never repeated.
The real trick is splitting data. Keep customers and orders in one big sheet and the same email ends up copied everywhere, so one missed edit makes the table contradict itself. Store each fact once, link tables with a foreign key, and change an email in exactly one place.
$ ls databases/
see all →
databases/what-is-a-database-index-find-one-row-without-reading-them-all.md
What is a database index? Find one row without reading them all
Ask a database for one person among a million rows and it could read every row until it finds them. That is slow. An index is the…
databases/your-first-sql-query-ask-a-table-of-pets-a-question.md
Your first SQL query: ask a table of pets a question
SQL is the language you use to ask a database questions, and five words get you surprisingly far: SELECT, FROM, WHERE, ORDER BY and LIMIT…