Lecture 2 — Data Models & Relational Algebra

Data models, DDL/DML/DCL/TCL, the relational model, keys, and the 6+ relational-algebra operators — with interactive playgrounds.

Sections

Quick summary

RELATIONAL MODEL:  Table = Relation, Row = Tuple, Column = Attribute
         Domain = allowed values · values are atomic · null = "unknown"
         Schema R = (A1, A2, …, An) ; instance = current rows

KEYS:    Super key  → enough to identify a tuple (may have extra attrs)
         Candidate  → a MINIMAL super key
         Primary    → one chosen candidate key
         Foreign    → value must appear as a key in another relation

DB LANGUAGES:  DDL (CREATE/ALTER/DROP)  DML (SELECT/INSERT/UPDATE/DELETE)
               DCL (GRANT/REVOKE)        TCL (COMMIT/ROLLBACK/SAVEPOINT)

RELATIONAL ALGEBRA — procedural; relations in → relation out:
   σ  Select    rows matching a predicate
   π  Project   chosen columns (dedupes)
   ∪  Union     (union-compatible)        − Difference      ∩ Intersection
   ×  Cartesian product                   ρ Rename
   ⋈  Natural join (match same-named cols)  θ-join (any condition)
   Outer joins: ⟕ left · ⟖ right · ⟗ full  (keep unmatched rows, fill NULL)