Ad Code

✨🎆 JOIN MERN, JAVA, PYTHON, AI, DEVOPS, SALESFORCE Courses 🎆✨

Get 100% Placement Oriented Program CLICK to new more info click

Database Testing


Database Testing Tutorial: Complete Guide, Checklist, Test Cases & Interview Questions (2026)

Database Testing is one of the most important parts of Software Testing. It verifies that data stored in a database is accurate, secure, consistent, and reliable.

Modern applications like Banking, E-Commerce, Healthcare, and Social Media depend on databases. A small database error can create major business problems.


What is Database Testing?

Database Testing is the process of testing database objects, data, and operations to ensure that the application stores and retrieves correct information.

Database testing verifies:

  • Data correctness
  • Data integrity
  • Database security
  • Database performance
  • Relationships between tables
  • Stored procedures and triggers

Real Time Example of Database Testing

Suppose a user creates an account in an online shopping application.

User Registration:

Name: Rahul Sharma
Email: rahul@gmail.com
Password: 123456

Database should store:

UserId | Name          | Email
--------------------------------
1      | Rahul Sharma  | rahul@gmail.com

Tester verifies:

  • User record created successfully
  • Email stored correctly
  • Duplicate email rejected
  • Password is encrypted
  • User can login successfully

Why Database Testing is Important?

  • Prevents data loss
  • Improves application quality
  • Finds database errors early
  • Improves application performance
  • Ensures data security

Types of Database Testing

1. Structural Database Testing

This testing checks database structure.

  • Tables
  • Columns
  • Data Types
  • Primary Keys
  • Foreign Keys
  • Constraints
Employee Table

EmployeeId INT PRIMARY KEY
Name VARCHAR(50)
Salary INT

2. Functional Database Testing

This verifies database functionality.

Example Login Query:

SELECT *
FROM Users
WHERE Email='test@gmail.com'
AND Password='12345'

Expected Result:

  • Valid user should login
  • Invalid user should be rejected

3. Data Integrity Testing

It verifies relationships between tables.

Customer Table

CustomerId
CustomerName


Order Table

OrderId
CustomerId
Amount

An order should not exist without a customer.

4. Database Performance Testing

Checks:

  • Query execution time
  • Database response time
  • Index performance

5. Database Security Testing

Checks:

  • User permissions
  • Authentication
  • Authorization
  • SQL Injection
Input:

' OR 1=1 --

Expected:
Login should fail

Database Testing Process

Step 1: Understand Database Design

  • Database Schema
  • ER Diagram
  • Table Relationship
  • Stored Procedures

Step 2: Prepare Test Data

CREATE TABLE Employee
(
EmployeeId INT PRIMARY KEY,
Name VARCHAR(50),
Salary INT
)
Insert Data:
INSERT INTO Employee
VALUES(1,'Amit',60000)

Complete Database Testing Checklist

Table Testing Checklist

  • ✓ Verify table exists
  • ✓ Verify table name
  • ✓ Verify columns
  • ✓ Verify datatype
  • ✓ Verify column size
  • ✓ Verify default values
  • ✓ Verify NULL values
  • ✓ Verify constraints

Primary Key Testing

  • Primary key exists
  • Duplicate values not allowed
  • NULL values not allowed
INSERT INTO Employee
VALUES(1,'John',50000)


Again:

INSERT INTO Employee
VALUES(1,'Alex',70000)

Expected: Duplicate Key Error

Foreign Key Testing

  • Relationship exists
  • Parent record required
  • Delete rules working

NULL Value Testing

INSERT INTO Employee(Name)
VALUES(NULL)

Expected: Insert should fail


Database CRUD Test Cases

Test Case 1: Insert Record

INSERT INTO Employee
VALUES(1,'Rahul',50000)

Expected: Record inserted successfully.

Test Case 2: Update Record

UPDATE Employee
SET Salary=70000
WHERE EmployeeId=1

Expected: Salary updated.

Test Case 3: Delete Record

DELETE FROM Employee
WHERE EmployeeId=1

Expected: Record deleted.

Test Case 4: Duplicate Record Testing

SELECT Email,COUNT(*)
FROM Users
GROUP BY Email
HAVING COUNT(*)>1

Expected: No duplicate records.


Transaction Testing

Example: Bank Money Transfer

BEGIN TRANSACTION

UPDATE Account
SET Balance=Balance-1000
WHERE Id=1


UPDATE Account
SET Balance=Balance+1000
WHERE Id=2


COMMIT

Verify:

  • Amount deducted once
  • Amount added once
  • Transaction completed

Rollback Testing

BEGIN TRANSACTION

UPDATE Account
SET Balance=Balance-5000

ROLLBACK

Expected: Previous data restored.


Important SQL Queries for Testers

Find Duplicate Data

SELECT Email,COUNT(*)
FROM Users
GROUP BY Email
HAVING COUNT(*)>1

Find NULL Records

SELECT *
FROM Users
WHERE Email IS NULL

Count Records

SELECT COUNT(*)
FROM Users

Database Testing Tools

  • SQL Server Management Studio
  • MySQL Workbench
  • Oracle SQL Developer
  • JMeter
  • LoadRunner
  • DBUnit

Database Testing Interview Questions

1. What is Database Testing?

Database testing verifies data accuracy, integrity, security, and performance.

2. What is Primary Key?

A primary key uniquely identifies each record in a table.

3. What is Foreign Key?

A foreign key creates a relationship between two tables.

4. Explain ACID Properties

  • Atomicity
  • Consistency
  • Isolation
  • Durability

5. DELETE vs TRUNCATE

DELETE: Removes selected rows and supports rollback.

TRUNCATE: Removes all records and is faster.


Final Database Testing Checklist


DATABASE TESTING CHECKLIST

✓ Table Verification
✓ Column Verification
✓ Data Type Validation
✓ Primary Key Testing
✓ Foreign Key Testing
✓ Constraint Testing
✓ NULL Testing
✓ Default Value Testing
✓ CRUD Testing
✓ Stored Procedure Testing
✓ Trigger Testing
✓ View Testing
✓ Index Testing
✓ Transaction Testing
✓ Rollback Testing
✓ Security Testing
✓ SQL Injection Testing
✓ Performance Testing
✓ Backup Testing
✓ Recovery Testing

Conclusion

Database Testing is a critical skill for every Software Tester. A strong understanding of SQL, database concepts, queries, and testing techniques helps testers identify defects and deliver reliable applications.

Labels: Database Testing, SQL Testing, Software Testing, QA Testing, Manual Testing

Post a Comment

0 Comments