Skip to content
Home » Database Integrity

Database Integrity

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:

  1. Domain Integrity
  2. Entity Integrity
  3. 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

  1. Data Types (INT, VARCHAR, DATE, etc.)
  2. CHECK constraints
  3. DEFAULT values
  4. NOT NULL constraints
  5. 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)NameAge
101Rahul20
NULL ❌Meena19
101 ❌Karan21

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
10CSE

EMPLOYEE

EmpIDEmpNameDeptID (FK)
201John10 ✔ valid
202Mary12 ❌ 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

ActionMeaning
CASCADEDelete/update child rows when parent is removed
SET NULLSet FK to NULL when parent is removed
SET DEFAULTSet FK to default value
RESTRICT / NO ACTIONPrevent 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 TypeEnsuresEnforced ByPrevents
DomainValid data valuesData types, CHECK, NOT NULLInvalid/meaningless values
EntityUnique, non-null primary keysPRIMARY KEYDuplicate or missing rows
ReferentialValid foreign key referencesFOREIGN KEYOrphan 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.