A domain is the set of legal values a column is allowed to hold — not just its data type, but the full range of what actually makes sense.
Why This Matters
- A data type alone (like "integer") doesn't fully capture what's actually valid — an age column being an integer doesn't stop -5 from being technically legal.
- Understanding domain as a concept is what motivates the constraints you'll formally learn to enforce a few chapters from now.
Core Concept
- A Domain is the complete set of acceptable values for a given attribute — for example, an "age" domain might be "non-negative integers up to some realistic maximum", not just "any integer".
- A column's data type is a rough, enforced approximation of its true domain — the type stops obviously wrong values (text in a number column), but not all logically wrong ones (a negative age).
Deep Dive
- The gap between "what the type allows" and "what actually makes sense" is exactly what constraints (CHECK, NOT NULL, and others, covered later in this course) exist to close.
- Two columns can share a data type but have completely different domains — a "rating" column and an "age" column might both be integers, but a rating's real domain is probably 1–5, while age's is 0–120 or so.
Common Mistakes
Trusting a column's data type to fully capture what values are actually valid.
Why: A type only rules out values of the wrong kind (text where a number belongs) — it says nothing about values of the right kind that are still nonsensical, like a negative price.
Fix: Think through a column's real domain deliberately, and enforce the parts a plain data type can't with an explicit constraint.
Interview Questions
What's the difference between a column's data type and its domain?
The data type is the broad category of value a column can hold (integer, text, date). The domain is the full, specific set of values that are actually valid for that column's real-world meaning — usually narrower than what the type alone allows.
Chapter Summary
A domain is the true set of valid values for a column — narrower than its data type usually allows on its own. The gap between the two is exactly what explicit constraints exist to close, later in this course.