StaffCoder
PostgreSQL
PostgreSQLPostgreSQL
4 modules · 12 challengesSign up
Module 2 of 4 · 4 challenges

PostgreSQL Constraints & Keys

Make the database enforce the rules: primary and unique keys, foreign keys with the right delete behaviour, named NOT NULL and CHECK rules, and rolling a rule out over legacy data.
Finish every challenge, or complete the star challenge, to complete the module.

Challenges

4 challenges

Duplicate Customers

Sign up to unlock
0%0 of 1 solvedeasy
About this challenge

Stop a merged customers table from taking the same id, the same email, or the same discount code twice - including global codes that carry no region.

Solved in a browser IDE and graded by tests. Sign up to solve

Orphaned Order Lines

Sign up to unlock
—No data yeteasy
About this challenge

Wire up an order book so lines cannot name a missing order, an order's lines go when the order goes, a product still on an invoice cannot be deleted, a retired category leaves its products behind, and a shipment must name a whole order line rather than half of one.

Solved in a browser IDE and graded by tests. Sign up to solve

Impossible Values Accepted

Sign up to unlock
—No data yeteasy
About this challenge

Give a bookings table named NOT NULL and CHECK rules, including one that judges two date columns together, and roll a rule out over a legacy table that already breaks it.

Solved in a browser IDE and graded by tests. Sign up to solve

Event Ticketing Schema

STAR
Solving it completes the module
—No data yeteasy
About this challenge

Build a ticketing schema whose rules the database enforces: primary keys, a unique venue name, a tier code unique per event and channel with nulls not distinct, references that cascade, refuse or clear, a two-column composite reference, named NOT NULL and CHECK rules, and a NOT VALID rule rolled out over a legacy table that already breaks it.

Solved in a browser IDE and graded by tests. Sign up to solve

We use cookies that are necessary to run Staffcoder, and optional analytics cookies to see which pages get used. Analytics stays off unless you accept. Read our Cookie Policy.