DEV Community

Joy Odinaka
Joy Odinaka

Posted on

Quality Assurance - SQL and Database Testing

I have learned how to test web applications and APIs.

But how do I know the data is actually stored correctly?

For example, when a user places an order:

  • Is the order saved?
  • Is the correct user linked to it?
  • Is the order total accurate?
  • Does the order status update correctly?
  • What happens if something goes wrong?

And I dived into SQL & Database Testing from quality assurance perspective.

Here are the fundamentals I learnt.


1. Database, DBMS & RDBMS

First step is to understand where application data lives.

  • Database: An organized collection of data.
  • DBMS: Software used to create, manage, and access databases.
  • RDBMS: A database management system that organizes data into related tables.

Examples of relational databases include MySQL, PostgreSQL, and SQL Server.

A food delivery application might have tables like:

Users
Restaurants
Food_Items
Orders
Order_Items
Enter fullscreen mode Exit fullscreen mode

These tables store related information about the application.


2. Understanding Basic SQL

SQL stands for Structured Query Language.

It's used to communicate with relational databases.

Some common commands include:

Command Purpose
SELECT Retrieve data
INSERT Add data
UPDATE Modify data
DELETE Remove data

For example, to retrieve all users:

SELECT * FROM users;
Enter fullscreen mode Exit fullscreen mode

To find a specific user:

SELECT * FROM users
WHERE email = 'joy@example.com';
Enter fullscreen mode Exit fullscreen mode

To update an order:

UPDATE orders
SET status = 'Cancelled'
WHERE id = 101;
Enter fullscreen mode Exit fullscreen mode

As a QA tester, I can use these queries to verify whether application actions produce the expected database changes.


3. Filtering & Sorting Data

Sometimes I don't need all the records.

I need specific information.

SQL provides operators such as:

  • WHERE
  • AND / OR
  • LIKE
  • IN
  • BETWEEN
  • ORDER BY

Example:

SELECT * FROM orders
WHERE status = 'Pending'
ORDER BY created_at DESC;
Enter fullscreen mode Exit fullscreen mode

This retrieves pending orders and sorts them from newest to oldest.

Useful when investigating specific test data.


4. SQL Joins

Related information is often stored in different tables.

JOIN allows us to retrieve related records from multiple tables.

For example, I want to see which users placed orders.

SELECT
    users.name,
    orders.id,
    orders.total
FROM users
JOIN orders
ON users.id = orders.user_id;
Enter fullscreen mode Exit fullscreen mode

This combines user information with their orders.

Common JOIN types include:

  • INNER JOIN
  • LEFT JOIN
  • RIGHT JOIN
  • FULL OUTER JOIN

Understanding joins helps me investigate relationships between application data.


5. Database Constraints

Constraints are rules that help maintain data accuracy and integrity.

Some common constraints:

Constraint Purpose
PRIMARY KEY Uniquely identifies a record
FOREIGN KEY Links related tables
UNIQUE Prevents duplicate values
NOT NULL Prevents missing values
CHECK Enforces a condition
DEFAULT Provides a default value

For example:

  • Two users shouldn't register with the same unique email.
  • An order shouldn't reference a nonexistent user.
  • An order total shouldn't be negative.
  • A new order should have a default status if one is specified by the database rules.

As a tester, I need to verify that these rules are enforced.


6. Database Testing & Data Integrity

Database testing helps verify that application data is accurate, consistent, and reliable.

Imagine a user places an order worth $3,000.

I should verify:

  • Was the order saved?
  • Is the correct user associated with it?
  • Is the total $3,000?
  • Are the correct food items recorded?
  • Is the initial status correct?

I can also compare API responses with database records.

The goal is to make sure the data shown by the application matches what's actually stored.


7. Aggregate Functions & Grouping

Sometimes I need to verify more than individual records.

SQL provides aggregate functions:

  • COUNT() — Counts records.
  • SUM() — Calculates totals.
  • AVG() — Calculates averages.
  • MIN() — Finds the minimum value.
  • MAX() — Finds the maximum value.

Example:

SELECT
    status,
    COUNT(*) AS total_orders
FROM orders
GROUP BY status;
Enter fullscreen mode Exit fullscreen mode

This shows how many orders exist under each status.

I can also use HAVING to filter grouped results.

Useful when testing reports, dashboards, and order summaries.


8. Database Transactions

A transaction is a group of database operations treated as one logical unit.

Two important commands:

  • COMMIT — Saves the transaction.
  • ROLLBACK — Undoes uncommitted changes.

For example, when placing an order, the system may need to create an order and reduce food inventory.

What happens if the order is created but the inventory update fails?

A properly designed transaction helps prevent partial changes from leaving the database inconsistent.

This is especially important when testing things like order processing and stock management.


What I Learnt

SQL and Database Testing have helped me understand that verifying the user interface or API response isn't always enough.

I also need to verify what happens to the data behind the scenes.

My testing approach is becoming:

UI → API → Database → Data Verification

Because an application can display a success message while storing incorrect information.

A successful operation should also leave the data in the correct state.


I have covered the fundamentals of Manual QA, Test Design, Test Execution, Test Planning, Web Testing, API Testing, and SQL & Database Testing.

Now it's time to move into Test Automation - yeeeaaaahhhhhhh.

I will start with the basics of automation tools and frameworks before getting into writing automated tests.

Notes can be found here.

I'm learning QA and I'm taking you with me.

Top comments (0)