Every time you book a train ticket on IRCTC, transfer money through UPI, or check your exam results online, you are trusting a database to hold information that is correct and unchanged. That trust is built on a quiet but powerful principle called data integrity. It is the set of rules and mechanisms that keep data accurate, complete, and reliable from the moment it enters a system until the moment someone reads it back. Without it, a database is just a pile of numbers and text that nobody can depend on. This post breaks down what data integrity really means, how a Database Management System (DBMS) validates and protects it, and why it is the backbone of every reliable application you use.
Table of Contents
- What data integrity actually means
- The main categories of integrity
- How a DBMS validates data integrity
- Declarative integrity constraints
- Triggers in Oracle
- How integrity maintains consistency and prevents anomalies
- The three classic anomalies
- Normalization as the structural defense
- Why this matters in practice
What data integrity actually means
Data integrity is the assurance that data stored in a database is correct, consistent, and trustworthy across its entire lifecycle. It is not a single feature you switch on. It is a combination of design rules, constraints, and procedures that work together so that the information you store today reads back exactly as intended tomorrow.
Three qualities define data with good integrity. First, correctness: the values stored must be accurate and follow the rules of the real world they represent, such as an age never being negative. Second, timeliness: the data must reflect the current state of things, so an outdated address or a stale account balance weakens integrity even if it was once correct. Third, relevance: the data must actually serve its purpose, with no junk or contradictory entries cluttering the system.
It helps to separate two related ideas. Data security protects information from unauthorized access. Data integrity protects information from being wrong, duplicated, or broken, whether the cause is a typing mistake, a software bug, or a half-finished transaction. According to Oracle’s documentation, maintaining integrity is a cornerstone function that the DBMS itself should enforce rather than leaving it to application code.
The main categories of integrity
Data integrity is usually enforced under a few well-defined categories, and understanding them makes the rest of the topic much clearer.
Entity integrity ensures that every row in a table can be uniquely identified. This is enforced through the primary key, which can never be null and must be unique. As explained by GeeksforGeeks, allowing a null primary key would make it impossible to pick out one specific row, defeating the purpose of the table.
Domain integrity controls the values allowed in a single column. A domain is simply the set of permitted values for an attribute. If a marks column should only hold numbers from 0 to 100, domain integrity rejects a value of 150 or the word “Twenty”. The column’s data type, default values, and CHECK rules all work to enforce this. Domain integrity focuses on the validity of individual column values rather than the uniqueness of rows.
Referential integrity keeps the relationships between tables synchronized. When a foreign key in one table points to a primary key in another, referential integrity guarantees that this link always stays valid. The relationship between tables must be preserved during every insert, update, and delete. Its main job is to prevent “orphan” records, such as an order that points to a customer who no longer exists.
User-defined integrity covers business rules that the standard categories cannot express, such as “a savings account balance cannot drop below 500 rupees”. These rules are typically implemented through triggers and stored procedures.
How a DBMS validates data integrity
A DBMS does not simply hope that users enter clean data. It actively validates every operation against the rules you have defined. There are two broad approaches: declarative constraints and procedural code.
Declarative integrity constraints
The cleanest way to enforce integrity is through declarative constraints. These are rules defined directly in the table structure using SQL, so the DBMS handles enforcement automatically with no extra programming. Oracle and other systems recommend this approach because the rules are easy to write and the database itself guarantees they are never bypassed.
The common constraints include the PRIMARY KEY, which combines uniqueness and a not-null rule to enforce entity integrity; the FOREIGN KEY, which enforces referential integrity by requiring a matching value in the parent table; the NOT NULL constraint, which forbids empty values; the UNIQUE constraint, which prevents duplicates while allowing one null; and the CHECK constraint, which restricts a column to values that satisfy a condition. As one overview puts it, these constraints turn the database into the enforcer of business rules, making data accuracy automatic rather than dependent on application code.
Triggers in Oracle
Sometimes a rule is too complex for a simple constraint. This is where triggers come in. A trigger is a block of PL/SQL code that runs automatically when a specific event, such as an INSERT, UPDATE, or DELETE, occurs on a table. Triggers can fire before or after the event, which lets developers validate or modify data at exactly the right moment.
In Oracle, triggers are used to enforce sophisticated integrity rules that ordinary constraints cannot handle. A trigger might check a value against another table, log every change for auditing, or block changes outside business hours. Oracle’s PL/SQL reference recommends using triggers to constrain data input mainly in two cases: enforcing referential integrity when parent and child tables sit on different nodes of a distributed database, and enforcing complex business rules that constraints cannot define.
A typical trigger structure looks like this in concept: CREATE OR REPLACE TRIGGER trigger_name BEFORE INSERT ON table_name FOR EACH ROW, followed by the validation logic. Oracle also fires statement-level triggers before row-level triggers and guarantees that triggers cannot compromise integrity constraints, keeping the firing sequence predictable.
There is an important caution here. Oracle advises against using triggers to duplicate rules that a simple declarative constraint could enforce. Triggers add complexity, can be harder to debug, and are easier to disable, so they should be reserved for logic that genuinely needs them. The guiding principle is simple: use a constraint when you can, and a trigger only when you must.
How integrity maintains consistency and prevents anomalies
The real payoff of data integrity is consistency. A consistent database is one where the same fact is never recorded in two contradictory ways. When integrity rules are weak or the table design is poor, the database becomes vulnerable to anomalies, which are errors that creep in during normal insert, update, and delete operations.
The three classic anomalies
An insertion anomaly happens when you cannot add a new record without also supplying unrelated or dummy data. For example, in a poorly designed table that mixes student and course details, you might be unable to add a new course unless at least one student has enrolled in it. You would be forced to insert null or fake student values just to record the course.
A deletion anomaly occurs when removing one record accidentally erases other important information. If a single table stores both customers and their orders, deleting a customer could wipe out the only record of a product they ordered. The unintended loss of related data is a direct threat to integrity.
An update anomaly arises when the same piece of information is stored in many places and a change is applied to only some of them. If a branch address is repeated across dozens of rows and you update only a few, the database now holds conflicting versions of the same fact.
Normalization as the structural defense
The standard cure for these anomalies is normalization, the process of organizing data into well-structured, related tables to reduce redundancy. Normalization splits a large, repetitive table into smaller logical tables linked by keys, so each fact is stored in exactly one place. When data is not duplicated, there is nothing to update inconsistently, nothing forced during insertion, and nothing lost during deletion.
Integrity constraints and normalization work as partners. Good table design removes the redundancy that breeds anomalies, while constraints and triggers guard the rules at runtime. Together they ensure that whether you are managing a college’s student records, a bank’s transactions, or a hospital’s patient files, the data stays reliable enough to act on with confidence.
Why this matters in practice
Consider a banking system where Customer IDs serve as primary keys. Entity integrity ensures no two customers share the same ID and no account exists without one. Referential integrity ensures every transaction links to a real account. Domain integrity ensures a deposit amount is a valid positive number. Strip away any of these and the consequences range from duplicate accounts to mismatched balances. The same logic protects university examination databases, government welfare records, and inventory systems across countless organisations. Reliable decisions can only be made on data you can trust, and integrity is what earns that trust.
What do you think? If you were designing a database for your college’s library or attendance system, which integrity rules would you treat as non-negotiable, and where might a trigger be worth the extra complexity over a simple constraint?
References
- https://docs.oracle.com/cd/E11882_01/server.112/e40540/datainte.htm
- https://www.geeksforgeeks.org/dbms/dbms-integrity-constraints/
- https://montecarlo.ai/blog-guide-to-domain-integrity-in-databases/
- https://opentextbc.ca/dbdesign01/chapter/chapter-9-integrity-rules-and-constraints/
- https://www.boardinfinity.com/blog/integrity-constraints-in-dbms/
- https://docs.oracle.com/en/database/oracle/oracle-database/26/lnpls/reasons-use-triggers.html
- https://docs.oracle.com/cd/B19306_01/server.102/b14220/triggers.htm
- https://docs.oracle.com/cd/A91202_01/901_doc/appdev.901/a88876/adg13trg.htm
- https://www.geeksforgeeks.org/dbms/anomalies-in-relational-model/
- https://www.geeksforgeeks.org/dbms/introduction-of-database-normalization/

Leave a Reply