SQL (SQLite engine)

Test a unique constraint violation

Medium70 pts~25 min
  • UNIQUE constraints
  • Collation
  • 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.

Test URL
/lab/database-testing-test-a-unique-constraint-violation

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

Objective

Prove customers.email rejects an exact duplicate, then expose that the constraint is case-sensitive.

Your task

  1. 1Insert a customer reusing customer 1's email exactly ('ava.thompson@example.com'); it must fail.
  2. 2Insert name 'Ava Upper', email 'AVA.THOMPSON@EXAMPLE.COM', country 'USA', created_at '2025-06-01'; note that it is accepted.
  3. 3Report case-insensitive duplicates: SELECT lower(email) AS email, COUNT(*) AS copies FROM customers GROUP BY lower(email) HAVING COUNT(*) > 1.

Acceptance criteria

  • The exact duplicate fails with UNIQUE constraint failed
  • The last result set reports the case-insensitive duplicate of ava.thompson@example.com

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