Skip to main content
Admissions guidance, study banks, and career tools — get started on Shalyam

Foreign Key With Cascade Delete

Create Orders so that order rows are deleted automatically when their customer is deleted. Orders has id (primary key), customer_id and amount.

Table schema

Customers(id INT PRIMARY KEY, name VARCHAR(50))

Sample data

Customers: (1, Aman)
Orders: (10, customer 1, 100)
Then: DELETE FROM Customers WHERE id = 1;

Discussion

No discussions yet.

Rewards · v2.1

Get Exclusive Insights with Every Issue

Join Shalyam Newsletter

Stay ahead in education, research, and innovation—straight to your inbox.