ACID properties mapped to SQL Server mechanisms: the transaction log and write-ahead logging, rollback and recovery, constraints, locks and row versioning, and durability on commit.
ACID is the promise a transaction makes. Atomicity: all of its changes happen or none do; SQL Server records every change in the transaction log and uses those records to roll back. Consistency: the database moves from one valid state to another, enforced by constraints, foreign keys and triggers. Isolation: concurrent transactions don't see each other's half-finished work, through locks or row versioning (RCSI, snapshot) depending on the isolation level. Durability: once COMMIT returns, the change survives a crash, because of write-ahead logging: the log is flushed to disk before commit is acknowledged, and recovery replays it.
The trade-off: stronger isolation and synchronous durability cost concurrency and latency, so you choose the isolation level deliberately.
"ACID is four guarantees a transaction gives you, and in SQL Server each one maps to a concrete mechanism. Atomicity and durability both come from the transaction log. Every change is written as a log record before the data page changes on disk, which is write-ahead logging. If the transaction fails or I roll it back, SQL Server walks the log backwards and undoes it. When I commit, SQL Server flushes the log buffer to disk and only then returns success, so if the server loses power a second later, crash recovery redoes the committed work from the log.
Consistency is mostly about the rules I declare: primary keys, foreign keys, unique and check constraints. They are checked inside the transaction, so a violation fails the statement. Isolation is the interesting one: by default SQL Server uses read committed, implemented with shared and exclusive locks, or with row versioning when read committed snapshot is on, which it is by default in Azure SQL Database. Higher levels like serializable hold more locks for longer.
The mistake I see is assuming a statement error rolls back the whole transaction. It doesn't by default: in T-SQL many errors only abort the statement, and the transaction carries on. That's why I put
SET XACT_ABORT ONat the top of every procedure that opens a transaction, and from .NET I always commit explicitly and dispose the transaction. ACID is only as good as the transaction boundaries you draw."
| Property | What it promises | SQL Server mechanism |
|---|---|---|
| Atomicity | All or nothing | Log records with undo information; ROLLBACK; undo phase of recovery |
| Consistency | Valid state to valid state | PK, FK, UNIQUE, CHECK constraints, triggers; checked per statement |
| Isolation | No interference from concurrent work | Locks (S, U, X, intent) or row versions in the version store |
| Durability | Committed data survives a crash | Write-ahead logging; log flush on commit; redo phase of recovery |
| Setting | Effect |
|---|---|
XACT_ABORT OFF (default) |
Some errors abort only the statement; the transaction can commit half the work |
NOLOCK / read uncommitted |
Gives up isolation: dirty reads, missing or double-counted rows |
| Delayed durability | Commit returns before the log flush; a crash can lose the last few milliseconds of commits |
| Disabled or untrusted constraints | Consistency is no longer enforced for existing rows |
An order import inserted the order header, then failed on one order line with a check-constraint error. Without XACT_ABORT, the procedure carried on and committed headers without lines, about [N] broken orders a week. Adding SET XACT_ABORT ON plus TRY...CATCH with THROW made each order all-or-nothing, and the broken orders stopped.
Checks that the candidate can connect each ACID property to a real SQL Server mechanism rather than reciting definitions.
Green flags
XACT_ABORT and statement-level abortsRed flags
NOLOCK is a harmless performance tipEvery database has a log file (.ldf). Each change produces a log record with a log sequence number (LSN), the transaction id, and enough information to redo and undo it.
BEGIN TRAN
UPDATE Stock ... -> log record LSN 100 (before/after image)
INSERT Orders ... -> log record LSN 101
COMMIT -> commit record LSN 102, log flushed to disk, then 'OK' to client
Data pages are changed in memory (the buffer pool) and written to the data file later by checkpoints or the lazy writer. That is safe because of write-ahead logging (WAL): a dirty page is never written to disk before the log records that describe it.
On ROLLBACK, or when the session dies, SQL Server reads the transaction's log records backwards and applies compensating changes. A long transaction therefore takes a long time to roll back, which is why killing a big batch job is not instant.
COMMIT writes a commit record and waits for the log block to be hardened (flushed). The wait shows as the WRITELOG wait type. After a crash, recovery runs three phases:
Analysis -> find active transactions and dirty pages
Redo -> replay logged changes from the oldest dirty page LSN
Undo -> roll back transactions that never committed
Accelerated Database Recovery (ADR), always on in Azure SQL Database, keeps row versions in a persistent version store so undo is near-instant instead of proportional to the transaction size.
The isolation level decides which anomalies (dirty reads, non-repeatable reads, phantoms) are possible.
The database enforces declared rules. A business rule that lives only in C#, such as "stock never goes below zero", is not part of ACID consistency unless you add a CHECK (Quantity >= 0) constraint or a conditional update.
T-SQL error behaviour is uneven: a constraint violation aborts the statement but not the batch unless XACT_ABORT is on. SET XACT_ABORT ON turns most runtime errors into a full rollback, and is what you want in nearly every transactional procedure. Note that compile errors and some errors are not caught by TRY...CATCH in the same scope.
CHECK (Quantity >= 0), run a transaction with two inserts where the second fails, with XACT_ABORT off and then on, and count the rows each time.SELECT * FROM sys.fn_dblog(NULL, NULL) (test database only) after a small update and find your transaction's log records.READ_COMMITTED_SNAPSHOT and repeat.sys.dm_os_wait_stats for WRITELOG before and after inserting 10,000 rows one transaction per row versus one transaction for all rows.Atomic order insert in T-SQL, and the same boundary from .NET with Microsoft.Data.SqlClient.
CREATE TABLE dbo.Stock (ProductId int PRIMARY KEY, Quantity int NOT NULL CHECK (Quantity >= 0));
CREATE TABLE dbo.Orders (OrderId int IDENTITY PRIMARY KEY, ProductId int NOT NULL REFERENCES dbo.Stock(ProductId), Quantity int NOT NULL);
GO
CREATE OR ALTER PROCEDURE dbo.PlaceOrder @ProductId int, @Quantity int
AS
BEGIN
SET NOCOUNT ON;
SET XACT_ABORT ON; -- any runtime error rolls back the whole transaction
BEGIN TRY
BEGIN TRAN;
UPDATE dbo.Stock SET Quantity -= @Quantity WHERE ProductId = @ProductId; -- CHECK keeps it >= 0
INSERT dbo.Orders (ProductId, Quantity) VALUES (@ProductId, @Quantity);
COMMIT; -- returns only after the log is hardened
END TRY
BEGIN CATCH
IF @@TRANCOUNT > 0 ROLLBACK;
THROW; -- surface the original error to the caller
END CATCH
END
namespace Shop.Data;
using Microsoft.Data.SqlClient;
public sealed class OrderWriter(string connectionString)
{
public async Task PlaceOrderAsync(int productId, int quantity, CancellationToken ct)
{
await using var conn = new SqlConnection(connectionString);
await conn.OpenAsync(ct);
// Dispose without Commit = rollback, so an exception can never leave half an order.
await using var tx = (SqlTransaction)await conn.BeginTransactionAsync(ct);
await using (var cmd = new SqlCommand(
"UPDATE dbo.Stock SET Quantity -= @q WHERE ProductId = @p;" +
"INSERT dbo.Orders (ProductId, Quantity) VALUES (@p, @q);", conn, tx))
{
cmd.Parameters.AddWithValue("@p", productId);
cmd.Parameters.AddWithValue("@q", quantity);
await cmd.ExecuteNonQueryAsync(ct);
}
await tx.CommitAsync(ct);
}
}
BEGIN TRAN rolls everything back. Why it is wrong: With XACT_ABORT OFF, a constraint violation aborts only that statement and the transaction can still commit. Instead: SET XACT_ABORT ON plus TRY...CATCH with ROLLBACK and THROW.NOLOCK to fix blocking. Why it is wrong: It drops isolation and returns uncommitted or duplicated rows. Instead: Use RCSI and shorten write transactions.WRITELOG), so throughput collapses. Instead: Commit in batches of a few thousand rows.Even for a junior question, the strong answer ties each letter to a mechanism, because that is what lets you reason about failures: a long rollback is the undo phase, WRITELOG waits are durability, blocking is isolation. Knowing that statement-level aborts are the default in T-SQL is the single most practical point.
Isolation is where ACID costs the most. Locking isolation makes readers and writers wait for each other, and serializable adds range locks that raise blocking and deadlocks; row versioning (RCSI, the Azure SQL Database default) removes reader/writer waits at the cost of version store space. ACID also stops at the database boundary: a transaction can't include a message broker or another service, so in microservices you use an outbox or a saga for cross-service consistency.
| Knob | When it fits | Cost | When not to |
|---|---|---|---|
XACT_ABORT ON |
Every procedure with a transaction | None meaningful | Rare cases needing to continue after an expected error (use TRY...CATCH instead) |
| RCSI | OLTP with readers blocked by writers | tempdb/version store space, small update overhead | Code that relies on readers blocking to stay correct |
| Serializable | Range rules such as 'no overlapping booking' | Range locks, deadlocks | As a default for every transaction |
| Delayed durability | High-volume, loss-tolerant logging tables | Can lose recent commits on crash | Money, orders, anything you can't recompute |
Isolation levels decide which anomalies a transaction can see. Read uncommitted takes no shared locks, so dirty reads are possible (it's what NOLOCK does). Read committed, the default, only reads committed data, using short-lived S locks, or row versions when RCSI is on, but a re-read can change (non-repeatable read). Repeatable read holds S locks to the end of the transaction, so rows you read can't change, but new rows can appear (phantoms). Serializable adds key-range locks so ranges can't change either. Snapshot gives a transaction-consistent view from row versions.
The trade-off: each step up holds more locks for longer, which means more blocking and deadlocks. Pick the lowest level that is correct, and solve specific races with targeted locks or constraints.
NOLOCK is read uncommitted: it reads rows other transactions haven't committed (which may be rolled back), and because it can use allocation-order scans without shared locks, it can skip rows or read them twice when pages split during the scan. It can even fail with error 601. It removes blocking by giving up correctness. Use read committed snapshot isolation (RCSI), the default in Azure SQL Database, so readers see the last committed version without blocking writers, and fix the long write transactions that cause blocking.
By default every SaveChanges is atomic: EF Core opens a transaction, sends all the INSERT/UPDATE/DELETE batches and commits, or rolls back on any failure (since EF Core 7 it skips the transaction when there is only one statement). You call Database.BeginTransactionAsync yourself only when several SaveChanges calls or raw SQL must commit together; inside that, EF Core takes a savepoint before each SaveChanges so one failed save can be undone without losing the rest. TransactionScope works but defaults to Serializable isolation, needs TransactionScopeAsyncFlowOption.Enabled for async, and cannot escalate to a distributed transaction on Azure SQL. With EnableRetryOnFailure, an explicit transaction must run inside CreateExecutionStrategy().ExecuteAsync, so the whole unit is retried. The trade-off: explicit transactions give you multi-step atomicity at the cost of longer-held locks and retry complexity, so prefer one SaveChanges per use case.
Last updated 23 Nov 2026.