Data Integrity in DBMS
Data Integrity in a Database Management System (DBMS) refers to the accuracy, consistency, and reliability of data stored in the database over its entire lifecycle. It ensures that data remains correct, valid, and trustworthy. Data integrity is maintained through constraints such as primary keys, foreign keys, unique constraints, and validation rules.
Example of Data Integrity
Consider the e-commerce schema:
Customers (
CustomerID INT PRIMARY KEY,
Name VARCHAR(100),
Email VARCHAR(100) UNIQUE
);
Orders (
OrderID INT PRIMARY KEY,
CustomerID INT,
OrderDate DATE,
FOREIGN KEY (CustomerID) REFERENCES Customers(CustomerID)
);
The PRIMARY KEY
on CustomerID
ensures each customer has a unique identifier.
The UNIQUE
constraint on Email
prevents duplicate email addresses.
The FOREIGN KEY
on Orders.CustomerID
ensures every order references an existing customer.
If an order with a CustomerID
not in the Customers
table is inserted, the DBMS rejects it, maintaining data integrity.
Data Inconsistency
Data Inconsistency occurs when different copies or instances of the same data do not match or contradict each other within the database. This often happens due to improper updates, concurrent transactions without proper controls, or design flaws, leading to unreliable and conflicting data.
Example Scenario of Data Inconsistency
Suppose the CustomerID
of a customer is updated in Customers
but not updated in related Orders
, due to missing referential integrity enforcement:
- In
Customers
:CustomerID = 101
, Name = John Doe - In
Orders
: An order exists withCustomerID = 999
(no matching customer)
This mismatch causes data inconsistency.
Potential Impact
- Incorrect reports due to invalid joins
- Application errors or failures
- Loss of user trust in data quality
- Increased maintenance effort
- Violation of business rules
Conclusion
Maintaining data integrity is essential for reliable database operations. Proper use of constraints and transactions prevents data inconsistency, which otherwise can severely affect business processes and decisions.