What is data integrity?
Data integrity is a database property that guarantees correctness, consistency, and reliability of information while it's being stored and processed.
The main types of integrity
- Entity Integrity
- Every record in a table must have a unique identifier (a primary key).
- This ensures there are no duplicate or "empty" records.
- Referential Integrity
- A foreign key's values must match existing values of the primary key in the other table.
- It prevents "orphaned references", for example, an employee can't reference a department that doesn't exist.
- Domain Integrity
- A field's values must match the allowed data type and constraints (e.g. number, text, date).
- For example, the
Agefield can't hold the text "thirty".
- User-defined Integrity
- Additional rules set by business logic, for example: a salary can't be negative.
Put simply, data integrity guarantees that the database holds truthful, logical, consistent information, and that no data operation breaks these rules.
Short Answer
Interview readyPremium
A concise answer to help you respond confidently on this topic during an interview.