Databases & SQL Interview Questions on Transactions, ACID and Isolation Levels

Reviewed by Mark Dickie · Last updated

5 questions on this page you can answer and see marked on the spot. Go to the first one

Database transactions are groups of SQL statements that succeed or fail as one unit. Interviewers use them to test whether you can explain ACID guarantees, reason about isolation levels, and spot the lock behaviour behind a deadlock. Be ready to walk through BEGIN, COMMIT and ROLLBACK, name which anomalies each isolation level still allows, and say what your database does by default. Most questions start from a concrete case, such as a bank transfer that fails halfway.

What does a transactions interview test in Databases & SQL?

Isolation levelAnomalies it still allowsNotes on common defaults
READ UNCOMMITTEDDirty readsPostgreSQL treats it as READ COMMITTED
READ COMMITTEDNon-repeatable reads, phantom readsPostgreSQL default
REPEATABLE READPhantom reads (standard SQL)MySQL InnoDB default
SERIALIZABLENoneCan raise serialization failures that the app must retry

How to practise transactions before the interview

  1. Write a transfer between two accounts inside BEGIN and COMMIT, then trigger a ROLLBACK when the balance check fails.
  2. Open two sessions, reproduce a non-repeatable read at READ COMMITTED, then rerun it at REPEATABLE READ.
  3. Build a deadlock by updating the same two rows in opposite order from two sessions, and read the error the server reports.
  4. Use SELECT ... FOR UPDATE on a read-then-write path and explain how it changes the race.

Key facts

  • Tarmac has 43 Databases & SQL interview questions on this topic, 10 of them on this page, at difficulty 2–5 of 5.
  • Tarmac tracked 3,405 job postings asking for Databases & SQL in November 2026.
  • Roles asking for Databases & SQL advertise a median base salary of £70,000, across 1,264 job postings as of November 2026.
  • Tarmac last reviewed these Databases & SQL interview questions on 9 November 2026.

At a glance

Questions10 shown · 43 in the bank
Difficulty2–5 of 5
FormatsTrue / false, Multiple answer, Ordering, Fill in the blank, Code output, Multiple choice, Short answer, Flashcard

What you'll review

  1. acid
  2. isolation levels
  3. locking
  4. mvcc

Practice questions

Try one before you open the answer. Pick an option and press Check; it's marked on the spot.

In a database that fully enforces ACID properties, the Atomicity guarantee means that a transaction is treated as an all-or-nothing unit: if the transaction is rolled back (whether explicitly by the application or automatically by the system), every change made within that transaction is undone, leaving the database as if the transaction never ran.#

Options

Show answer

True. In a fully ACID-compliant database, atomicity means a rollback undoes every change the transaction made, whether the application requested it or the system triggered it. The transaction behaves as an all-or-nothing unit, so the database ends up as if the transaction never ran.

Why:

Atomicity means a transaction is an indivisible unit: either all of its changes take effect when it commits, or none of them do. A rollback, whatever triggered it, is the mechanism that enforces this, so every change the transaction made is undone and the database returns to its state before the transaction began. The statement only describes what a rollback does once it happens, so it is true regardless of whether the application requested the rollback or the system initiated it. It makes no claim about when a rollback is triggered, so no particular product's error-handling behavior affects the answer.

A banking application runs the following two transactions concurrently on a database that uses READ COMMITTED isolation:#

Options

Pick every one that applies.

Show answer

Under READ COMMITTED isolation, lost updates, non-repeatable reads, and phantom reads can still occur. READ COMMITTED only prevents dirty reads by ensuring a transaction never sees uncommitted changes from another. It does not prevent two transactions from both reading the same stale value and overwriting each other (lost update), seeing a committed change between two reads (non-repeatable read), or a committed insert/delete changing a range result (phantom read).

Why:

READ COMMITTED prevents dirty reads by only exposing committed data. However, it does NOT prevent lost updates (two transactions can both read the old value, compute independently, and the second write silently overwrites the first), non-repeatable reads (a committed update by another transaction between two reads of the same row in T1 produces different values), or phantom reads (a committed insert/delete by another transaction causes a range query to return a different result set). SERIALIZABLE or application-level locking is required to prevent all three.

Place the following steps in the order a WAL-based engine (e.g., PostgreSQL or InnoDB) performs them for a single transaction with strict durability (synchronous commit enabled), from first to last:#

Put these in order

Show answer

In a WAL-based engine such as PostgreSQL or InnoDB, a committed transaction proceeds as follows: DML statements modify buffer pages and generate redo records, the application issues COMMIT, the commit record is appended to the WAL buffer, the WAL is fsynced to durable storage, and only then is success returned. Writing dirty data pages to data files happens later and is not on the commit path.

Why:

The sequence is fixed by causality within one transaction. DML statements must run before the application can issue COMMIT. COMMIT triggers the engine to append a commit record to the WAL buffer, since the transaction's outcome must be logged. The engine must then flush the WAL through that commit record to durable storage before it can acknowledge success, which is the write-ahead durability guarantee under strict durability. Only after the fsync completes does the engine return success to the application. Dirty data pages are deliberately excluded because their writeback is asynchronous and can occur before or after commit, so it has no fixed position in this total order.

Complete the following statements about ACID properties:#

Show answer

Complete the following statements about ACID properties:

  1. The Atomicity property ensures that a transaction either completes in full or has no effect at all — partial updates are never visible.
  2. The Isolation property guarantees that concurrent transactions produce a result equivalent to running them one at a time in some serial order.
  3. The Durability property ensures that once a transaction is committed, its effects survive system failures such as power loss or crashes.
Why:

ACID stands for Atomicity, Consistency, Isolation, and Durability. Atomicity ensures all-or-nothing execution (e.g., both a debit and a credit succeed or neither does). Isolation ensures concurrent transactions don't interfere in a way that violates serializability guarantees (at whatever isolation level is configured). Durability ensures committed data survives failures, typically via write-ahead logging and fsync. Consistency is the fourth property but refers to business-rule invariants being preserved, not described in these blanks.

PostgreSQL (current version). Table accounts(id, balance) holds the row (1, 100). Two sessions run interleaved in the order shown. What two values does Session A's two SELECTs return, in order? Write them one per line.#

-- Session A
BEGIN ISOLATION LEVEL READ COMMITTED;
SELECT balance FROM accounts WHERE id = 1;   -- A1

-- Session B
BEGIN;
UPDATE accounts SET balance = 150 WHERE id = 1;
COMMIT;

-- Session A
SELECT balance FROM accounts WHERE id = 1;   -- A2
COMMIT;
Show answer
100
150
Why:

In PostgreSQL's READ COMMITTED level, each statement gets a fresh snapshot when it starts, not the transaction as a whole. A1 runs before B's update, so it returns 100. B then commits the change to 150. A2 takes a new snapshot that includes B's committed write, so it returns 150. This is a non-repeatable read, and READ COMMITTED allows it. Under REPEATABLE READ, the transaction would keep the snapshot taken at its first statement, and both reads would return 100.

Which ACID property is directly responsible for defining the four standard isolation levels (READ UNCOMMITTED, READ COMMITTED, REPEATABLE READ, SERIALIZABLE), and what problem does each level mitigate?#

Options

Show answer

Isolation is the ACID property that controls how concurrent transactions interact with each other's uncommitted data. The four standard isolation levels (READ UNCOMMITTED, READ COMMITTED, REPEATABLE READ, SERIALIZABLE) are all refinements of this guarantee, each trading off anomaly protection (dirty reads, non-repeatable reads, phantom reads) against concurrency throughput.

Why:

ACID's Isolation property is the one that governs how concurrent transactions see each other's in-progress changes. The four standard isolation levels (READ UNCOMMITTED, READ COMMITTED, REPEATABLE READ, SERIALIZABLE) are all refinements of the Isolation guarantee. Atomicity ensures all-or-nothing completion; Consistency ensures data remains valid after a transaction; Durability ensures committed changes survive crashes. None of the other three properties concern themselves with concurrency anomalies like dirty reads, non-repeatable reads, or phantoms — those are isolation concerns.

A hospital database has a rule: at least one doctor must be on call at all times. Currently, doctors Alice and Bob are both on call.#

Options

Show answer

Write skew is the anomaly in this scenario. Both transactions read the same on-call rows, each decided it was safe to deactivate one doctor, and each updated a different row, so no write-write conflict occurred. PostgreSQL 16's REPEATABLE READ is snapshot isolation and does not detect this, so the invariant breaks. Only SERIALIZABLE prevents it.

Why:

Each transaction reads the same two on-call rows and sees a count of 2, so each one, working alone from its own snapshot, correctly keeps at least one doctor on call. The two UPDATEs touch different rows (Alice and Bob), so there is no write-write conflict for PostgreSQL to detect, and both commit. The combined result has zero doctors on call, which violates the invariant even though each transaction preserved it on its own. This is write skew. The anomaly is not a dirty read, because no transaction reads uncommitted data, and not a lost update, because neither UPDATE overwrites the other's row. It is not a phantom, because no rows are inserted or deleted; both transactions read the same existing rows. PostgreSQL 16's REPEATABLE READ is snapshot isolation, which does not track read dependencies between concurrent transactions, so it permits this outcome. Only SERIALIZABLE, which uses serializable snapshot isolation to detect the dangerous dependency, prevents it, by aborting one transaction with a serialization failure (SQLSTATE 40001).

Explain how a typical relational database engine (e.g., PostgreSQL or MySQL InnoDB) implements the Durability guarantee of ACID at a technical level. Your answer should:#

Show answer

Relational engines implement Durability with a write-ahead log (WAL), called the redo log in InnoDB. Before the engine acknowledges a COMMIT, the WAL records for that transaction, including its commit record, must be written and flushed to durable storage. In PostgreSQL this flush is an fsync/fdatasync call; in InnoDB with innodb_flush_log_at_trx_commit=1 the log is flushed at each commit. Modified data pages can stay in the buffer pool and be written lazily, because crash recovery replays (redoes) committed WAL records to rebuild any pages not yet on disk. With fsync = off, PostgreSQL stops issuing those flush calls. WAL is still written with write() into the OS page cache, but the engine no longer knows when it reaches disk, so a COMMIT can be acknowledged while its record exists only in volatile memory. A crash then loses that commit. The larger danger is that without flush ordering, data pages and WAL can reach disk out of order or partially, so recovery cannot rely on the log and the database can be corrupted. By contrast, synchronous_commit=off still flushes WAL in order, only asynchronously, so it risks losing the most recent commits but does not corrupt the database.

Why:

Durability is provided by a write-ahead log (the redo log in InnoDB). The WAL record for a transaction, including its commit record, must be flushed to durable storage before the engine acknowledges COMMIT, while data pages may be written lazily and rebuilt from the log by replay after a crash. Setting fsync=off in PostgreSQL stops the engine from issuing fsync/fdatasync calls. WAL is still written into the OS page cache with write(), but the engine has no guarantee of when it reaches disk, so acknowledged commits can vanish on a crash. Because writes can also reach disk out of order or partially, data pages can end up ahead of the WAL, which makes recovery impossible and corrupts the database. This is different from synchronous_commit=off, which flushes WAL in order but asynchronously, so it only risks losing the most recent commits. In InnoDB, innodb_flush_log_at_trx_commit=1 is the setting that gives full durability.

What is a deadlock, and what is the standard way to reduce how often deadlocks happen?#

Show answer

A deadlock is two (or more) transactions each holding a lock the other needs, so neither can proceed; the database detects the cycle and aborts one as the victim. The standard mitigation is to have all transactions acquire locks on rows/tables in a consistent global order, plus keeping transactions short and retrying the aborted one.

Why:

Deadlocks arise from circular lock waits. The database resolves them by killing a victim transaction (which the application should retry), but you reduce their frequency by always locking resources in the same order and minimizing the time locks are held.

In a database using MVCC (for example PostgreSQL), one transaction is reading a row while another transaction updates that same row and commits. Explain how the reader still sees a consistent value without blocking on the writer.#

Show answer

Under MVCC each update writes a new version of the row instead of overwriting it in place, and every transaction reads against a snapshot fixed at its start (or per statement). The reader sees the row version that was committed as of its snapshot, so the writer's newer committed version is simply invisible to it. Because the reader consults the older version rather than waiting for a lock, reads never block writes and writes never block reads.

Why:

MVCC keeps multiple committed versions of a row and gives each transaction a snapshot that determines which version it can see. The reader's snapshot predates the writer's commit, so it reads the old version and gets a consistent view, while the writer creates a new version concurrently. This version-plus-snapshot design is what lets readers and writers proceed without blocking each other — the defining advantage over lock-based concurrency.

Sources

The official documentation these questions are checked against:

Related interview questions

Job market

See databases-sql salaries and hiring demand from live job postings.

The other 33 questions

This page shows 10 and marks what you pick. That's as far as a page can go. A free account opens the other 33 and keeps every answer. What you miss comes back until it's right: after a day, then at longer gaps.

Start with this topic

Free · the whole bank · 100 answers per 30 days, each marked with written feedback

Interview booked? Practise the job ad instead

What moved, monthly

One email a month when the bulletin comes out: what moved in the markets we track, and the new question topics we published. Confirm your address to join. Unsubscribe any time.