mediumShopee · schema-design
Link orders to customers with an enforced, cascading foreign key
customers and orders exist as two separate tables, but nothing stops orders.customer_id from pointing at a customer that doesn't exist — the two tables aren't actually linked at the database level yet.
Add a FOREIGN KEY from orders.customer_id to customers.id. A customer who closes their account should have their orders removed automatically, so the constraint needs ON DELETE CASCADE.
Schema
▸customers
| id | INT |
| name | TEXT |
▸orders
| id | INT |
| customer_id | INT |
| amount | NUMERIC |
Example input
▸customers
▸orders
Stuck? Ask the coach for a nudge that won't give the answer away, or reveal the reference solution and a short walkthrough of why it works.