Course contentsShow
← Computer Science
Lesson 1554 of 2,87236. Database FundamentalsFree lesson

Domains and Data Types

Defining domains as the set of allowed values for attributes and mapping them to concrete data types in databases.

Domains and Data Types

What you'll learn: How domains define the universe of allowed values for database attributes and how they map to concrete data types.


In relational databases, every column (attribute) in a table has a domain — the complete set of legal values that can appear in that column. Think of a domain as the rulebook that defines what's allowed: for an "age" column, the domain might be "non-negative integers less than 200," while for an "email" column, it's "strings matching email format."

From Abstract Domain to Concrete Data Type

Domains are conceptual boundaries, but databases need something more practical to enforce them. That's where data types come in. A data type is the concrete implementation the database uses to store and validate values.

For example:

  • Domain: "Employee ages" (0 to 120)
  • Data type: INTEGER or SMALLINT

The data type INTEGER provides the storage mechanism and basic validation (must be a whole number), but it doesn't automatically enforce that the value is between 0 and 120 — that requires additional constraints.

Why This Matters

Choosing the right data type is crucial for:

  • Storage efficiency: CHAR(2) for US state codes vs. VARCHAR(255) wastes space
  • Integrity: Using DATE for birthdates prevents invalid entries like "32nd of March"
  • Performance: Operations on integers are faster than text comparisons
  • Clarity: The schema communicates intent (a BOOLEAN clearly means yes/no)

Common data types include INTEGER, VARCHAR, DATE, DECIMAL, BOOLEAN, and TIMESTAMP — each representing different domains of values.

Key Takeaway: Domains define what values are meaningful for an attribute, while data types provide the database mechanism to store and initially validate those values — choosing appropriate data types is the first step in enforcing domain constraints.