Data Integrity

Data integrity refers to the accuracy, consistency, and reliability of data stored in a database by enforcing constraints and validation rules.

Data integrity ensures that data remains accurate and valid throughout its lifecycle. It is enforced using:

  • Primary keys (uniqueness)
  • Foreign keys (referential integrity)
  • Constraints (NOT NULL, CHECK, UNIQUE)
  • Transactions (ACID properties)

Example Constraint for Data Integrity:

sqlCopyEditCREATE TABLE Employees (
    emp_id INT PRIMARY KEY,
    salary DECIMAL(10,2) CHECK (salary > 0)
);

This ensures that salary values cannot be negative.