Resource library

QA Interview

Database Testing Interview Questions and Answers

Database testing interview questions and answers covering schema, CRUD, ACID, referential integrity, stored procedures, ETL migration, and performance testing.

2,584 words | Article schema | FAQ schema | Breadcrumb schema

Overview

Database testing is where quality goes deeper than the screen. The application layer can look flawless while the data underneath is corrupted, inconsistent, or silently losing writes, and only someone testing the database itself will catch it. Interviewers ask about it to find testers who understand data integrity, transactions, and the failure modes of the persistence layer, not just how to write a SELECT.

This guide is for QA engineers and SDETs preparing for roles where the data layer is in scope: back-end heavy products, financial systems, data pipelines, and anything where a wrong number is a serious defect. It covers what database testing actually verifies, from schema and constraints to ACID properties, stored procedures, and data migrations, with the answers interviewers are listening for.

Where the SQL round is about writing clever queries, this is about strategy: what to test, why it matters, and how to catch the data bugs that never surface in the UI. Learn to talk about the database as a system with its own contracts to verify, and you will read as a tester who protects the most valuable thing the company owns, its data.

What Database Testing Is and Why It Matters

Open with a clean definition. Database testing validates the data layer directly: that data is stored correctly, retrieved accurately, constrained properly, and survives failures. It checks the schema, the constraints, the business logic embedded in stored procedures and triggers, and the integrity of relationships between tables, independent of what the UI displays.

Explain why it is a distinct discipline. A bug at the data layer is often invisible until it compounds: a missing constraint lets bad data accumulate, a broken trigger silently skips an audit row, a migration truncates a column. These defects are expensive because they corrupt the source of truth and can spread to every downstream system. Testing the database is how you catch them at the source rather than in a production incident weeks later.

  • DB testing validates storage, retrieval, constraints, and integrity directly.
  • It covers schema, constraints, stored procedures, triggers, and relationships.
  • Data-layer bugs are often invisible in the UI until they compound.
  • The database is the source of truth, so its defects are the most expensive.

Types of Database Testing

Interviewers like a structured taxonomy, so know the three buckets. Structural testing verifies the schema itself: tables, columns, data types, keys, indexes, and constraints match the design. Functional testing verifies behavior from the user perspective: a business action produces the correct data changes across tables. Non-functional testing covers performance, load, and security of the data layer.

Give an example of each to prove you can apply the taxonomy. Structural: confirming an `email` column is `VARCHAR(255) NOT NULL UNIQUE`. Functional: verifying that placing an order inserts the order, decrements inventory, and writes a payment row consistently. Non-functional: checking that a report query stays under a threshold at ten times the data volume. Mapping tests to these categories shows you plan coverage deliberately, not ad hoc.

  • Structural: schema, data types, keys, indexes, and constraints match the design.
  • Functional: business actions produce correct, consistent data changes.
  • Non-functional: performance, load, and security of the data layer.
  • Being able to classify a test shows deliberate coverage planning.

Structural Testing: Schema and Constraints

Schema testing is the foundation, so expect specifics. You verify column names, data types, sizes, nullability, default values, primary keys, foreign keys, unique constraints, and indexes against the agreed design or data dictionary. A mismatch (a phone number stored as `INT`, a `status` column that allows NULL when it should not) is a defect that will bite later, so you catch it at the schema level.

Bring up that schema testing matters most during change. When a migration alters a table, you verify the new column exists with the right type and default, existing data was preserved and back-filled correctly, and dependent views or procedures still resolve. Framing schema testing as change validation, not a one-time check, shows you understand where these bugs actually occur: in migrations, not in greenfield tables.

  • Verify types, sizes, nullability, defaults, keys, and indexes against the design.
  • A wrong type or a wrongly nullable column is a real defect.
  • Schema testing matters most during migrations and table alters.
  • Confirm dependent views and procedures still resolve after a change.

CRUD and Data Integrity Testing

CRUD testing is the functional core: for each entity, verify Create, Read, Update, and Delete behave correctly and leave the data consistent. Create should persist exactly what was submitted with correct defaults and generated keys; Read should return accurate data; Update should change only the intended fields; Delete should remove the right rows and handle related data per the rules (cascade or restrict).

Push into data integrity, the part juniors skip. After each operation you verify not just the target row but the invariants: totals still reconcile, counts stay consistent, no partial writes remain, and no orphaned child rows were created or left behind. The strong answer frames CRUD testing as verifying that every write leaves the database in a valid state, which is the real contract the data layer must uphold.

  • Verify Create, Read, Update, and Delete each behave correctly and consistently.
  • Create persists exact values, defaults, and generated keys.
  • Delete removes the right rows and handles related data (cascade or restrict).
  • After every write, confirm invariants hold: no partial writes or orphans.

ACID Properties: The Transaction Round

The transaction round centers on ACID, and you should define all four crisply with a testing angle. Atomicity: a transaction is all or nothing, so verify that a failure midway rolls everything back with no partial changes. Consistency: a transaction moves the database from one valid state to another, respecting all constraints. Isolation: concurrent transactions do not corrupt each other. Durability: once committed, data survives a crash or power loss.

Make it concrete with the canonical example: a bank transfer debits one account and credits another. Atomicity means that if the credit fails, the debit is rolled back so money is never lost. To test it, you force a failure between the two steps and assert both accounts are unchanged. Interviewers reward tying each property to a test you would actually run, especially the atomicity rollback and the isolation-under-concurrency cases.

  • Atomicity: all or nothing; force a mid-transaction failure and assert full rollback.
  • Consistency: every transaction leaves a valid state respecting constraints.
  • Isolation: concurrent transactions do not corrupt each other.
  • Durability: committed data survives a crash; test with a forced restart.

Referential Integrity and Constraint Testing

Referential integrity is a favorite because it is where real data rots. Foreign keys enforce that a child row (an order) references an existing parent (a customer). You test that the database rejects an insert with a non-existent foreign key, and that deletes behave per the defined rule: CASCADE removes children, RESTRICT blocks the delete, and SET NULL nulls the reference. The bug you hunt is orphaned rows: children whose parent no longer exists.

Extend to other constraints as validation targets: UNIQUE (no duplicate emails), NOT NULL (required fields rejected when empty), CHECK (a value stays in range, like a non-negative price), and DEFAULT (the right value applied when omitted). Your job is to prove each constraint both accepts valid data and rejects invalid data. Testing the rejection path, not just the happy path, is what makes constraint testing meaningful.

  • Foreign keys: reject invalid references; verify CASCADE, RESTRICT, and SET NULL on delete.
  • Hunt orphaned rows, the classic referential-integrity defect.
  • Test UNIQUE, NOT NULL, CHECK, and DEFAULT constraints explicitly.
  • Prove each constraint rejects bad data, not just that it accepts good data.

Testing Stored Procedures, Triggers, and Views

Business logic often lives in the database, so interviewers check you can test it. Stored procedures are testable units: call them with valid inputs, boundary values, and invalid inputs, and assert the returned data and the side effects on tables. Treat a stored procedure like any function under test, with input partitions and edge cases, not as an untouchable black box.

Triggers are trickier because they fire implicitly on insert, update, or delete. You test them by performing the triggering action and verifying the secondary effect happened: an audit row written, a denormalized total updated, a timestamp set. The common trigger bug is silent failure or firing the wrong number of times, so you assert exact side effects. For views, verify they return correct, current data and that the filtering and joins in the view definition are right.

  • Test stored procedures like functions: valid, boundary, and invalid inputs.
  • Assert both return values and side effects on the tables.
  • Test triggers by performing the action and verifying the implicit side effect.
  • Watch for triggers that fail silently or fire the wrong number of times.

ETL and Data Migration Testing

For data-heavy roles, ETL and migration testing is a major topic. When data moves from a source to a destination (a warehouse load, a system migration), you verify three things: completeness (all expected rows arrived, usually a source-to-target count reconciliation), correctness (values transformed per the mapping rules), and integrity (relationships and keys preserved). The headline check is that no rows were dropped or duplicated in transit.

Go deeper on transformations, where the subtle bugs live: data-type conversions that truncate, timezone or encoding shifts, rounding on numeric fields, and NULLs mapped incorrectly. You test with reconciliation queries comparing source and target, boundary records (maximum lengths, special characters), and a full re-run to confirm idempotency. Framing migration testing as prove nothing was lost or silently altered is exactly what interviewers want to hear, because migrations are famous for quiet data loss.

  • Verify completeness (row counts reconcile), correctness (mapping rules), and integrity.
  • The headline check: no rows dropped or duplicated in transit.
  • Hunt transformation bugs: truncation, timezone, encoding, rounding, NULL mapping.
  • Test boundary records and re-run to confirm idempotency.

Performance, Indexes, and Concurrency

Non-functional questions probe whether you think about the data layer under stress. Performance testing here means checking that critical queries stay fast as data grows: you run them against production-scale volumes, read the execution plan (`EXPLAIN`) to confirm indexes are used, and flag full table scans on large tables. A query that is instant on 100 rows and unusable on 10 million is a defect you catch before launch, not after.

Concurrency is the other half. You test that simultaneous transactions do not deadlock, lose updates, or read dirty data, which ties back to isolation levels. A classic case is two users updating the same row: you verify the database serializes them correctly and no update is silently lost. Mentioning execution plans, missing indexes, and concurrency (deadlocks and lost updates) shows you test the database as a system under load, not just a passive store.

  • Test critical queries at production-scale volume, not toy data.
  • Read `EXPLAIN` plans to confirm index use and catch full table scans.
  • Test concurrency: deadlocks, lost updates, and dirty reads.
  • A query fast on 100 rows and slow on 10 million is a defect to catch early.

Tools and Automation for DB Testing

Expect a tooling question. You do not need a huge list, but name the categories: a SQL client or IDE for exploratory checks, a data-comparison tool for reconciliation, and, crucially, automating DB assertions inside your test framework. In practice you connect via JDBC or a driver and assert query results in the same test that drove the UI or API, so a single test verifies end to end.

Mention keeping database tests repeatable, the hard part. Techniques: seed a known dataset before tests, wrap each test in a transaction that rolls back, or use a disposable database (a container via Testcontainers) so every run starts clean. The strong answer connects DB testing to the same isolation discipline as any automation: independent, repeatable, and self-cleaning, so tests do not corrupt each other data and pass or fail on their own merits.

  • Use a SQL client for exploration and a data-comparison tool for reconciliation.
  • Automate DB assertions inside your test framework via JDBC or a driver.
  • Verify end to end: one test drives the UI or API and asserts the data.
  • Keep tests repeatable with seeded data, transaction rollback, or a disposable DB.

Scenario and Behavioral Questions

Scenario: after a release, users report their profile changes sometimes do not save. How do you investigate at the data layer? Reproduce it and check whether the row updates at all, whether a trigger or constraint silently rejects it, whether a transaction is rolling back on a hidden error, and whether a caching layer is masking the true stored value. Structured elimination across those layers is the answer, not just re-testing the UI and hoping.

Behavioral prompts probe care with data. You may be asked how you test against production-like data safely. Cover using masked or synthetic data rather than real PII, running destructive tests only against dedicated test databases, and never validating by mutating production. Showing that you treat data as sensitive and shared, with privacy and safety in mind, is as important as the technical depth, especially for finance or healthcare roles.

  • Investigate silent write failures across rows, triggers, transactions, and caching.
  • Use structured elimination, not just repeated UI retries.
  • Test with masked or synthetic data, never real PII where avoidable.
  • Run destructive tests only on dedicated test databases.

Frequently Asked Questions

What is database testing?

Database testing validates the data layer directly: that data is stored, retrieved, and constrained correctly and survives failures. It covers the schema, constraints, stored procedures, triggers, and relationships between tables, independent of what the application UI displays.

What are the types of database testing?

Three categories: structural testing (schema, data types, keys, indexes, constraints), functional testing (business actions produce correct, consistent data changes), and non-functional testing (performance, load, and security of the data layer). Interviewers like you to classify your tests this way.

What are ACID properties and how do you test them?

Atomicity (all or nothing), Consistency (valid state to valid state), Isolation (concurrent transactions do not corrupt each other), and Durability (committed data survives a crash). Test atomicity by forcing a mid-transaction failure and asserting a full rollback, and isolation by running concurrent transactions against the same row.

What is the difference between database testing and SQL testing?

SQL skill is writing queries; database testing is the broader discipline of validating the data layer, including schema, constraints, ACID transactions, stored procedures, triggers, and migrations. SQL is a tool you use within database testing, but database testing is about test strategy for the data as a system.

How do you test data migration or ETL?

Verify completeness (source-to-target row counts reconcile), correctness (values transformed per the mapping rules), and integrity (keys and relationships preserved). Hunt transformation bugs like truncation, timezone shifts, and rounding, test boundary records, and re-run to confirm no rows are dropped or duplicated.

How do you keep database tests repeatable?

Seed a known dataset before tests, wrap each test in a transaction that rolls back afterward, or use a disposable database such as a container so every run starts clean. The goal is the same isolation discipline as any automation: independent, repeatable, and self-cleaning tests.

Related QAJobFit Guides