Referential integrity is a concept in relational database management that ensures the consistency and accuracy of data by enforcing relationships between tables. It guarantees that a foreign key in one table always refers to a valid primary key in another table, preventing orphaned records and maintaining the logical connections between related data.

Key Points:

Example:

Consider two tables, orders and customers, where orders has a foreign key customer_id that references the primary key id in the customers table.

CREATE TABLE customers (
    id INT PRIMARY KEY,
    name VARCHAR(100)
);

CREATE TABLE orders (
    order_id INT PRIMARY KEY,
    order_date DATE,
    customer_id INT,
    FOREIGN KEY (customer_id) REFERENCES customers(id)
);

In this example, referential integrity ensures that every customer_id in the orders table corresponds to a valid id in the customers table. If you try to insert an order with a customer_id that does not exist in the customers table, the database will reject the operation, thus maintaining referential integrity.