1. The relational model
A relation is a table: a set of tuples (rows) over a fixed list of attributes (columns). Each attribute has a domain of atomic values. The schema is ; the degree (arity) is , and the cardinality is the number of tuples.
Because a relation is a set: there are no duplicate tuples and tuple order does not matter. SQL tables are bags (multisets): duplicates stay unless you write DISTINCT.
Keys:
- Superkey: a set of attributes whose values differ for every pair of tuples.
- Candidate key: a minimal superkey (no proper subset is a superkey).
- Primary key: the candidate key chosen by the designer; cannot be NULL.
- Foreign key: attributes in one relation whose values must appear as a key in the referenced relation (or be NULL).
NULL means unknown or not applicable. Any comparison with NULL (even NULL = NULL) gives UNKNOWN, a third truth value. WHERE and HAVING keep a row only if the condition is TRUE.
| TRUE | UNKNOWN | FALSE | |
|---|---|---|---|
| NOT | FALSE | UNKNOWN | TRUE |
| TRUE AND x | TRUE | UNKNOWN | FALSE |
| FALSE OR x | TRUE | UNKNOWN | FALSE |