Test a foreign key constraint
Medium70 pts~25 min
- Foreign keys
- Negative testing
Practice app · Acme Commerce DB
A real SQL database (SQLite engine) seeded with an e-commerce and HR dataset, with schema browser and query runner.
Your starter code already declares TEST_URL — never hardcode a host.
Objective
Verify orders and order_items reject references to parents that do not exist.
Your task
- 1Insert an order for customer_id 999 (order_date '2025-12-30', status 'pending', total 10); it must fail.
- 2Insert an order_items row for order 1 with product_id 999; it must fail too.
- 3Verify nothing was stored: SELECT (SELECT COUNT(*) FROM orders) AS orders, (SELECT COUNT(*) FROM order_items) AS order_items.
Acceptance criteria
- An insert fails with FOREIGN KEY constraint failed
- The last result set shows the original counts (60 orders, 150 items)
Constraints
- Every run starts from a freshly seeded database, so your script must include its own setup statements.
- A failing statement is recorded and the script keeps running, so you can trigger an error and verify afterwards.
- Only the last result set of your script is compared, so finish with the verification query.
SQL (SQLite engine) · Database Testing · Constraints & keys