liveBook · Manning

Atomicity

As explained in 100 SQL Server Mistakes and How to Avoid Them

Atomicity is the transaction property that makes all of a transaction's operations succeed or fail as one unit.

Atomicity makes every statement in a transaction commit or roll back as one logical unit. The statements either all succeed or all fail, protecting multi-step updates from partial completion. section 7.1 section 1.2.1

Mistake: assuming BEGIN TRANSACTION guarantees automatic cleanup after an error.

  • A stored procedure can leave a transaction open when an operation fails. Check SELECT @@TRANCOUNT; an unexpected value of 1 means the transaction still needs an explicit ROLLBACK. section 7.1
  • Use structured error handling, including TRY...CATCH and an explicit rollback path, so failures do not leave the transaction active. section 7.1

Sales-order insertion

InsertSalesOrder begins a transaction before inserting sales-order data. A valid execution completes the order; an invalid product ID raises a foreign-key error, showing why the procedure needs a rollback-aware error path.

How 100 SQL Server Mistakes and How to Avoid Them covers it

How deep it goes
Defines all-or-nothing behavior, demonstrates open-transaction failures, and defers broader transaction nuances to isolation and durability.
Examples
Demonstrates sales-order insertion, invalid tables, foreign-key violations, @@TRANCOUNT checks, and TRY...CATCH procedures.
What it assumes
Assumes basic T-SQL and stored procedures while defining transactions and ACID properties at a basic level.
What you can do after
Diagnose unfinished transactions with @@TRANCOUNT and implement rollback-aware TRY...CATCH handling around multi-statement updates.
How it connects
Connects atomicity with transactions, ACID, error handling, locking, isolation levels, and the transaction log.

Also explained in

Compare how 13 books explain atomicity →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of 100 SQL Server Mistakes and How to Avoid Them. The section links point to the parts of the book it draws on.