Code Room
Code reviewMedium
Question
Review this SQL. Deleting a single customer takes 40 seconds and locks up the orders table.
What a strong answer looks like
Separate real bugs from style. Rank issues by severity, point at the root cause rather than the symptom, and suggest a concrete fix — specific and kind.
Learn the concepts
CREATE TABLE orders ( id BIGSERIAL PRIMARY KEY, customer_id BIGINT NOT NULL REFERENCES customers(id) ON DELETE CASCADE, total NUMERIC, created TIMESTAMPTZ);-- orders has 200M rows; the only index is the primary key. DELETE FROM customers WHERE id = $1;Run or narrate your approach, then ask the coach.