Database Testing with SQL

Harry · 21 Sep 2026 · 1 views
Log in to track your progress and mark lessons complete.

Introduction to Database Testing

UIs lie; databases do not. Verify that every action writes correct, complete rows and that bad actions write nothing.

SQL Every Tester Must Know

-- order + user + totals check
SELECT o.id, u.email, SUM(i.qty*i.price) AS total
FROM orders o JOIN users u ON u.id=o.user_id
JOIN order_items i ON i.order_id=o.id
GROUP BY o.id, u.email;

-- orphans: items without an order
SELECT * FROM order_items
WHERE order_id NOT IN (SELECT id FROM orders);

CRUD and Data Integrity Testing

  • Create - register user, row exists with hashed password, never plain text.
  • Read - filters/sorts/pagination match direct queries.
  • Update - edit profile updates exactly one row, audit fields change.
  • Delete - cancel order removes items (cascade) or blocks with a clear rule.
  • Constraints - NULL, unique, foreign keys reject bad writes.

Stored Procedures and Migrations

  • Execute procedures with edge inputs; verify outputs and side effects.
  • After migrations: row counts match, checksums spot-check, rollback script tested.

API + Database Testing Together

The golden loop: call POST /api/orders, assert 201, then query the DB for the same order, totals and stock decrement. UI, API and DB must agree.

Database CRUD verification table with create read update delete checks

Key Points

  • Always verify writes with SELECT, not just the UI message.
  • Test constraints by trying to break them.
  • API plus DB assertions catch bugs UIs hide.
Share this post:

Comments (0)

Please login or register to comment.

Create a free account to keep reading

You've enjoyed a free tutorial! Register (it's free) to unlock every tutorial, track your progress and save code.

or sign in with your account

Already have an account? Log in