Database Management System (DBMS) / Relational Model

Domain Constraints

🎯 What is Domain Constraints?

A Domain Constraint restricts the set of valid values that an attribute (column) in a table can take.

It ensures that the data entered is appropriate, meaningful, and valid according to the attribute's data type and rules.

A Domain Constraint specifies that the value of every attribute must be drawn from a defined domain (set of permissible values).


🎯 Purpose of Domain Constraints:

  • βœ… Prevent invalid data from being entered

  • πŸ”’ Enforce data consistency

  • πŸ” Help in data validation

  • πŸ”„ Ensure values are appropriate to the field


🧾 Examples of Domain Constraints

Column

Allowed Domain (Constraint)

Example Valid Values

Age

Integer between 0 and 120

25, 18 βœ…

Email

String with email format

abc@gmail.com βœ…

Gender

Only 'Male', 'Female', 'Other'

'Female' βœ…

DOB

Date only

2005-06-12 βœ…

Phone

10-digit number

9876543210 βœ…


πŸ§ͺ Example SQL Implementation:

CREATE TABLE Student (
  StudentID INT PRIMARY KEY,
  Name VARCHAR(50),
  Age INT CHECK (Age >= 0 AND Age <= 120),
  Gender VARCHAR(10) CHECK (Gender IN ('Male', 'Female', 'Other')),
  Email VARCHAR(100)
);

🧩 What Makes Up a Domain?

A domain can be defined by:

  • Data type (e.g., INT, VARCHAR, DATE)

  • Size/Length (e.g., VARCHAR(50))

  • Permissible values (e.g., CHECK (Grade IN ('A', 'B', 'C')))

  • Constraints (e.g., NOT NULL, CHECK)


βœ… Summary:

Feature

Description

πŸ“˜ Definition

Limits values in a column to valid data

🧠 Based on

Data type, format, length, condition

βš™οΈ Implemented using

Data types + CHECK, IN, NOT NULL

❌ Prevents

Invalid, illogical, or out-of-range data