Databases & SQL Interview Questions: Transactions and ACID
Reviewed by Mark Dickie · Last updated
7 questions on this page you can answer and see marked on the spot. Go to the first one
Database transactions are groups of reads and writes that succeed or fail as one unit. ACID names four guarantees: atomicity, consistency, isolation, and durability. Isolation draws the most follow-up questions, because the isolation level decides which anomalies (dirty reads, non-repeatable reads, phantoms) your query can still see. Expect to explain how PostgreSQL delivers durability with write-ahead logging and isolation with MVCC snapshots.
What do transaction questions test in a SQL interview?
| Isolation level | Anomalies it still allows | Default in common engines |
|---|---|---|
| READ UNCOMMITTED | Dirty reads | Not a real level in PostgreSQL, which treats it as READ COMMITTED |
| READ COMMITTED | Non-repeatable reads, phantom reads | PostgreSQL, Oracle, SQL Server |
| REPEATABLE READ | Phantom reads under the SQL standard; PostgreSQL's snapshot also blocks them | MySQL InnoDB |
| SERIALIZABLE | None, but may abort with a serialization failure you must retry | Opt-in in PostgreSQL, Oracle, SQL Server and MySQL; the default in SQLite |
Work through these by hand before you start the quiz:
- Open two psql sessions, begin a transaction in each, and update the same row in both to watch the second statement block on the row lock.
- Reproduce a lost update with a read-modify-write of a counter, then fix it with SELECT ... FOR UPDATE.
- Run a write skew example (two on-call doctors, each checking the other is still on duty) under REPEATABLE READ and then SERIALIZABLE, and note which one raises a serialization failure.
- Put a SAVEPOINT inside a transaction, fail a later statement, and confirm that only the work after the savepoint rolls back.
Key facts
- Tarmac has 15 Databases & SQL interview questions on this topic, 10 of them on this page, at difficulty 1–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 3 December 2026.
At a glance
| Questions | 10 shown · 15 in the bank |
|---|---|
| Difficulty | 1–5 of 5 |
| Formats | True / false, Fill in the blank, Multiple answer, Ordering, Multiple choice, Short answer |
What you'll review
- acid
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.
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.
Complete the following sentence describing ACID properties:#
Show answer
Complete the following sentence describing ACID properties:
The Durability property ensures that once a transaction has been committed, its changes will survive even a system crash or power failure. The Isolation property ensures that concurrent transactions produce results as if they were executed one after another in some serial order.
Durability guarantees that committed transactions persist permanently — typically achieved through write-ahead logging or other crash-recovery mechanisms — so that even a power failure cannot lose committed data. Isolation ensures that the intermediate states of a transaction are invisible to other concurrent transactions, making the final result equivalent to some serial execution order.
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).
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.
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:
- The Atomicity property ensures that a transaction either completes in full or has no effect at all — partial updates are never visible.
- The Isolation property guarantees that concurrent transactions produce a result equivalent to running them one at a time in some serial order.
- The Durability property ensures that once a transaction is committed, its effects survive system failures such as power loss or crashes.
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.
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.
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.
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.
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.
A transaction updates one row and then commits. Considering only the log-related steps (the in-memory change to the data page is excluded from this ordering), arrange the following steps in the order the database engine must perform them so that the commit is durable before the client is told it succeeded. Use the Write-Ahead Logging rule that a commit is durable only once its COMMIT record is on durable storage.#
Put these in order
Show answer
The required order is: write the update's log record to the log buffer, then write the COMMIT record, then flush the log to durable storage, then acknowledge the commit to the client. Write-ahead logging requires the COMMIT record to be durable before the client is told the transaction succeeded, so the flush must complete before acknowledgment.
The update's log record must enter the log before the COMMIT record, because the log is a sequential record of changes and the commit must follow the changes it covers. The COMMIT record must be in the buffer before the flush so that the flush covers it. The fsync must complete before acknowledgment, since a client must never be told a transaction committed when a crash could still erase its COMMIT record. Each adjacent pair has a strict precedence, so this is the single total order. The page-modification and optional page write-back steps are deliberately excluded, because their placement relative to the log steps is not fixed by the protocol.
In PostgreSQL, which of the following anomalies can still occur under the REPEATABLE READ isolation level? Select all that apply.#
Options
Pick every one that applies.
Show answer
Write skew is the only listed anomaly that can still occur under PostgreSQL's REPEATABLE READ isolation level. Snapshot isolation prevents dirty, non-repeatable, and phantom reads, and it blocks lost updates on the same row by raising a serialization error. Write skew slips through because two transactions update different rows, so no row-level conflict is detected.
Under PostgreSQL's REPEATABLE READ, each transaction reads from a snapshot fixed at the start of its first statement, so it never sees uncommitted data (dirty reads are impossible), never sees a changed row's new version on re-read (non-repeatable reads are impossible), and never sees newly inserted rows in a re-run range scan (phantoms are impossible). For the read-modify-write lost update, the second transaction's UPDATE targets a row that a concurrent transaction has already modified; PostgreSQL makes it wait for the first to finish and then raises could not serialize access due to concurrent update, so the increment cannot be silently overwritten. Write skew is the anomaly that remains: the two transactions read overlapping data but update different rows, so no row-level write conflict is detected and both commit, violating the application invariant. Preventing it requires SERIALIZABLE (SSI), or explicit locking such as SELECT ... FOR UPDATE on the rows read, or a constraint-based approach; this question excludes explicit locking, so the keyed answer is the write-skew scenario.
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 5 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 5 and keeps every answer. What you miss comes back until it's right: after a day, then at longer gaps.
Free · the whole bank · 100 answers per 30 days, each marked with written feedback