SQL (SQLite engine)

Test an update is atomic

Medium70 pts~25 min
  • Statement atomicity
  • CHECK constraints
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.

Test URL
/lab/database-testing-test-an-update-is-atomic

Your starter code already declares TEST_URL — never hardcode a host.

Objective

Show that a multi-row UPDATE is all-or-nothing: when one row violates a constraint, no row is changed.

Your task

  1. 1Run a flat $30 discount on every accessory: UPDATE products SET price = price - 30 WHERE category = 'accessories'.
  2. 2Several accessories cost less than 30, so price >= 0 is violated and the statement fails.
  3. 3Verify nothing was half-applied: SELECT id, price FROM products WHERE category = 'accessories' must show the original prices.

Acceptance criteria

  • The UPDATE fails with CHECK constraint failed
  • The last result set shows every accessories price unchanged
  • The script updates products

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 · CRUD & data integrity