Test a check constraint
Medium70 pts~25 min
- CHECK constraints
- Boundary values
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
Probe the CHECK constraints on employees and order_items with invalid values and verify none got through.
Your task
- 1Insert employee first_name 'Zero', last_name 'Salary', email 'zero.salary@acme.example', department_id 2, salary 0, hire_date '2025-12-01', status 'active'; it must fail.
- 2Insert the same employee with salary 70000 but status 'retired'; it must fail.
- 3Set quantity = 0 on order_items id 1; it must fail.
- 4Verify: SELECT (SELECT COUNT(*) FROM employees WHERE salary <= 0 OR status NOT IN ('active','inactive','on_leave')) AS bad_employees, (SELECT COUNT(*) FROM order_items WHERE quantity <= 0) AS bad_items.
Acceptance criteria
- A statement fails with CHECK constraint failed
- The last result set is (0, 0)
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