SQL
Database Management
ON UPDATE RESTRICT
Foreign Key Constraints
Database Integrity

What does ON UPDATE RESTRICT do?

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

ON UPDATE RESTRICT is a foreign-key rule that blocks changes to a referenced parent key when dependent child rows still point to it. In plain terms, if the parent key is in use, the database refuses the update rather than allowing the relationship to become invalid.

Where It Appears

You use ON UPDATE RESTRICT when defining a foreign key:

sql
1CREATE TABLE customers (
2    customer_id INT PRIMARY KEY,
3    name VARCHAR(100) NOT NULL
4);
5
6CREATE TABLE orders (
7    order_id INT PRIMARY KEY,
8    customer_id INT NOT NULL,
9    FOREIGN KEY (customer_id)
10        REFERENCES customers(customer_id)
11        ON UPDATE RESTRICT
12);

Here, orders.customer_id depends on customers.customer_id. The RESTRICT action controls what happens if someone tries to update a parent customer_id.

What the Database Does

Suppose the tables contain this data:

sql
1INSERT INTO customers (customer_id, name)
2VALUES (1, 'Alice');
3
4INSERT INTO orders (order_id, customer_id)
5VALUES (1001, 1);

Now try to change the parent key:

sql
UPDATE customers
SET customer_id = 2
WHERE customer_id = 1;

With ON UPDATE RESTRICT, that statement fails because the child row in orders still references customer_id = 1.

The database is protecting referential integrity by refusing the update.

Why You Would Use It

RESTRICT is appropriate when parent identifiers should be considered stable. In many schemas, primary keys are not supposed to change casually. If they do change, it is often a sign of bad modeling or an operation that should be handled with much more care.

Using ON UPDATE RESTRICT makes that rule explicit:

  • parent identifiers are not casually rewritten
  • child relationships must stay valid
  • accidental key changes fail fast

This is often the right default for lookup tables, account IDs, and other reference-heavy data.

How It Differs from CASCADE

ON UPDATE CASCADE does the opposite. Instead of blocking the update, it propagates the new key value to all matching child rows:

sql
FOREIGN KEY (customer_id)
    REFERENCES customers(customer_id)
    ON UPDATE CASCADE

With CASCADE, updating customers.customer_id from 1 to 2 would also update orders.customer_id from 1 to 2.

That can be convenient, but it is a very different policy. RESTRICT says "do not permit this change while dependents exist." CASCADE says "permit it, and rewrite dependents too."

RESTRICT Versus NO ACTION

In many databases, RESTRICT and NO ACTION behave similarly for non-deferrable constraints. The subtle difference is theoretical timing: RESTRICT is usually checked immediately, while NO ACTION can defer the check until statement or transaction end in systems that support deferred constraints.

In everyday application code, though, many developers see them behave the same and assume they are identical. They are conceptually close, but the exact semantics depend on the database engine.

Real-World Design Advice

If you find yourself frequently needing to update primary keys that are referenced elsewhere, that is often a schema smell. Surrogate keys such as integer IDs or UUIDs are typically chosen precisely so they can remain stable while names, codes, or business identifiers change in separate columns.

For example, instead of changing a referenced customer_id, you may want:

  • immutable customer_id
  • editable customer_code
  • editable display_name

That avoids the need for foreign-key update policies to do heavy lifting in the first place.

Common Pitfalls

The most common mistake is assuming RESTRICT only affects deletes. It applies to updates of the referenced key as well, which matters when someone tries to rename or renumber a parent identifier.

Another issue is debugging the wrong table. The update fails on the parent row, but the reason lives in the child table that still references it. When troubleshooting, always inspect the dependent rows.

Finally, do not choose RESTRICT or CASCADE mechanically. The right action depends on whether the parent key is intended to be stable or whether child rows should automatically track parent-key changes.

Summary

  • 'ON UPDATE RESTRICT prevents updates to a referenced parent key while child rows still depend on it.'
  • It preserves referential integrity by failing the update instead of propagating it.
  • It is a good fit when referenced identifiers are meant to stay stable.
  • 'ON UPDATE CASCADE is the alternative when child keys should update automatically.'
  • If key updates are common, the schema may need a more stable identifier design.

Course illustration
Course illustration

All Rights Reserved.