Browse SQL Topics ▼

Foreign Key Actions (CASCADE, RESTRICT)

📂 Schema Design & DDL 📘 Lesson 69 of 81

Configure cascade actions - ON DELETE CASCADE, ON DELETE RESTRICT, and ON DELETE SET NULL.

Foreign Key Actions (CASCADE, RESTRICT) is an essential topic in SQL and relational database engineering.

Overview

Building on foundational principles introduced in create-table-ddl, mastering foreign key actions (cascade, restrict) provides the core mental model and practical query skills needed for production relational database engineering.

CREATE TABLE order_items (
    id SERIAL PRIMARY KEY,
    order_id INT REFERENCES orders(id) ON DELETE CASCADE,
    product_id INT REFERENCES products(id) ON DELETE RESTRICT
);

Key Concepts

  • Understand the fundamental syntax, conventions, and mental model.
  • Avoid common beginner traps, data type mismatches, and performance pitfalls.
  • Apply practical idioms directly in production applications.

[!TIP] Master this concept to build a rock-solid foundation. Next, proceed to alter-table-ddl.

Test your understanding of Foreign Key Actions (CASCADE, RESTRICT)

Quick interactive practice questions with instant feedback.

Take Quiz →