Below is a clear, complete, and exam-oriented explanation of Database Integrity Constraints, covering Domain Integrity, Entity Integrity, and Referential Integrity — perfect for 5, 8, or 10-mark answers.
⭐ Database Integrity Constraints
Integrity constraints in a database ensure that the data stored is accurate, consistent, and reliable.
They prevent invalid data entry and maintain correctness across tables.
The three fundamental integrity constraints are:
- Domain Integrity
- Entity Integrity
- Referential Integrity
These constraints are part of the Relational Model defined by E. F. Codd.
⭐ 1. Domain Integrity
✔ Definition
Domain integrity ensures that the values in a column (attribute) are valid, meaningful, and within the allowed range.
Each attribute has a domain, i.e., a set of allowed values.
✔ Purpose
- Prevents wrong or inappropriate data
- Ensures data consistency
- Maintains valid formats and ranges
✔ How Domain Integrity is enforced
- Data Types (INT, VARCHAR, DATE, etc.)
- CHECK constraints
- DEFAULT values
- NOT NULL constraints
- User-defined domains
✔ Examples
- Age must be integer between 0 and 120
- Salary must be positive
- Email must follow proper format
- DateOfBirth must be prior to current date
SQL example:
Age INT CHECK (Age BETWEEN 0 AND 120),
Salary DECIMAL CHECK (Salary > 0),
Email VARCHAR(200) NOT NULL
✔ Summary
Domain Integrity ensures data follows valid data types, valid ranges, formats, and meaningful values.
⭐ 2. Entity Integrity
✔ Definition
Entity Integrity ensures that every table (relation) has a primary key, and no part of the primary key can be NULL.
✔ Purpose
- Guarantee unique identification of each record
- Prevent duplicate or missing entities
- Maintain correctness of key-based queries
✔ Rule
- Primary Key = UNIQUE + NOT NULL
✔ Example
In the STUDENT table:
| RollNo (PK) | Name | Age |
|---|---|---|
| 101 | Rahul | 20 |
| NULL ❌ | Meena | 19 |
| 101 ❌ | Karan | 21 |
Neither NULL nor duplicates are allowed in the primary key.
SQL example:
PRIMARY KEY (RollNo)
✔ Summary
Entity Integrity ensures each row is unique and identifiable.
⭐ 3. Referential Integrity
✔ Definition
Referential Integrity ensures that foreign key values must match existing primary key values in the referenced table OR be NULL (if allowed).
It maintains valid references between related tables.
✔ Purpose
- Prevent orphan records
- Maintain logical links between tables
- Ensure consistent relationships
✔ Example
Tables:
DEPARTMENT
| DeptID (PK) | DeptName |
|---|---|
| 10 | CSE |
EMPLOYEE
| EmpID | EmpName | DeptID (FK) |
|---|---|---|
| 201 | John | 10 ✔ valid |
| 202 | Mary | 12 ❌ invalid (no DeptID=12) |
DeptID=12 does not exist in Department table → referential integrity violation.
✔ Enforced using FOREIGN KEY constraint
FOREIGN KEY (DeptID)
REFERENCES Department(DeptID)
ON DELETE CASCADE
ON UPDATE CASCADE;
✔ Referential Integrity Actions
| Action | Meaning |
|---|---|
| CASCADE | Delete/update child rows when parent is removed |
| SET NULL | Set FK to NULL when parent is removed |
| SET DEFAULT | Set FK to default value |
| RESTRICT / NO ACTION | Prevent deletion of referenced row |
✔ Summary
Referential Integrity ensures that foreign key values always refer to valid existing primary key values.
⭐ Comparison Table (Exam-Friendly)
| Integrity Type | Ensures | Enforced By | Prevents |
|---|---|---|---|
| Domain | Valid data values | Data types, CHECK, NOT NULL | Invalid/meaningless values |
| Entity | Unique, non-null primary keys | PRIMARY KEY | Duplicate or missing rows |
| Referential | Valid foreign key references | FOREIGN KEY | Orphan records, broken links |
⭐ Perfect 5-mark Summary
Integrity constraints ensure correctness and consistency of data in a relational database.
Domain Integrity ensures attribute values are valid using data types and CHECK constraints.
Entity Integrity requires that every table has a primary key and that the primary key cannot be NULL or duplicated.
Referential Integrity ensures that foreign key values in one table correctly reference existing primary key values in another table.
Together, these constraints maintain accurate, reliable, and logically consistent data across the database.
