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
🧱
Data Models
Relational, ER, hierarchical, network, OO & semi-structured models.
⌨️
Database Languages
DDL, DML, DCL, TCL — purpose, commands & examples.
🔑
Relational Model & Keys
Relation, tuple, attribute, schema, domain, null & all key types.
∑
Relational Algebra
Select, project, union, difference, product, join, rename — with worked tables.
🎯
Practice & Simulations
Sample questions with answers plus step-through operation simulations.
🧮
RA Playground
Apply σ, π, ∪, ∩, −, ×, ⋈ live on sample relations.
🛢️
SQL Playground
Run real SQL on seeded tables in your browser (SQLite/WASM).
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)