Referential integrity ensures that relationships between related tables remain valid, typically by requiring foreign key values to reference existing primary or unique key values.
Maintaining valid relationships prevents orphan records and protects the consistency of business data.
An Order.CustomerID should reference an existing Customer.CustomerID.
CREATE TABLE Orders (
OrderID INT PRIMARY KEY,
CustomerID INT,
OrderAmount DECIMAL(12,2),
FOREIGN KEY (CustomerID)
REFERENCES Customers(CustomerID)
);
Important in banking, financial systems, customer databases, inventory systems, and enterprise applications.
- Referential integrity protects table relationships.
- Foreign keys commonly enforce relationships.
- Parent keys must satisfy the referenced constraint.
- It helps prevent orphan records.
- Rules can differ between database systems.
What is referential integrity?
It ensures that relationships between related tables remain valid.
Which database feature commonly enforces referential integrity?
Foreign key constraints commonly enforce referential integrity.