Understanding Transaction Basics

The definition of a transaction is "a logical unit of work." In real terms, a transaction is one or more statements that are executed together as a group. SQL Server guarantees that a transaction will succeed or fail completely. You will never get a partial transaction.

When you go to an ATM to make a $50 withdrawal, that act is treated as a transaction. The transaction consists of two parts:

  • The debit of $50 from your bank account

  • The delivery of $50 cash into your hand

It's clear that both parts of the transaction should be completed, or neither should occur. If you get $50 but your account is not debited, the bank is unhappy. If your account is debited, but no money comes out of the machine, you are not happy. ...

Get Sams Teach Yourself Transact-SQL in 21 Days, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.