Computer Science · Cheatsheet
Topic 8 · Databases (HL Option)
Chapter 2 · Going deeper & exam practice
📋 Reference · always available
Table
Row = record/tuple. Column = attribute/field. Each row UNIQUE by primary key.
Primary Key (PK)
Column(s) uniquely identifying each row. Often an auto-increment integer.
Foreign Key (FK)
Column referencing the PK of ANOTHER table. Links tables. Enforces REFERENTIAL INTEGRITY.
JOIN
Combine rows from 2+ tables on matching key. INNER (only matches), LEFT (all left + matches), etc.
1NF
Atomic values only (no lists in cells); each row unique.
2NF
1NF + every non-key column depends on the FULL primary key.
3NF
2NF + non-key columns depend ONLY on PK, not on other non-key columns.
Why normalise
Eliminate redundancy → no UPDATE/INSERT/DELETE anomalies → data consistency.
Denormalise
Reverse for warehouses: duplicate columns to make analytical queries fast.
SQL SELECT
`SELECT cols FROM table WHERE cond GROUP BY g HAVING agg-cond ORDER BY col LIMIT n`.
ACID
Atomicity (all or nothing) · Consistency (valid state) · Isolation (concurrent = serial) · Durability (survives crash).
Transaction
Group of operations that succeed/fail TOGETHER. BEGIN/COMMIT/ROLLBACK.
Common exam trap
Confusing PK (uniqueness) with FK (foreign reference). Both are 'keys' but very different roles.