@@ -16,7 +16,47 @@ a transaction.
1616Atomicity
1717=========
1818
19- .. todo: entire transaction must finish, or revert the database to old state.
19+ Transactions are often composed of multiple statements. Atomicity guarantees
20+ that each transaction is treated as a single "unit", which either succeeds
21+ completely, or fails completely: if any of the statements constituting
22+ a transaction fails to complete, the entire transaction fails and the database
23+ left unchanged. A guarantee of atomicity prevents updates to the database from
24+ occurring only partially, which can cause greater problems, than rejecting the
25+ whole series outright.
26+
27+ As an example, there are few rows in an accounting table:
28+
29+ .. table:: accounting
30+
31+ +-----------+-----------------+---------+
32+ | person_id | name | balance |
33+ +===========+=================+=========+
34+ | ... | ... | ... |
35+ +-----------+-----------------+---------+
36+ | 529 | Dora Headstrong | $1,000 |
37+ +-----------+-----------------+---------+
38+ | 402 | Toby Mugwort | $100 |
39+ +-----------+-----------------+---------+
40+ | ... | ... | ... |
41+ +-----------+-----------------+---------+
42+
43+ In case, Dora wants to transfer $100 to Toby, this can be split into
44+ 3 statements:
45+
46+ - Check if $100 is available
47+ - Deduct $100 from Dora's balance
48+ - Add $100 to Toby's balance
49+
50+ In case the 3rd statement fails, the data may stay as:
51+
52+ +-----------+-----------------+---------+
53+ | 529 | Dora Headstrong | $900 |
54+ +-----------+-----------------+---------+
55+ | 402 | Toby Mugwort | $100 |
56+ +-----------+-----------------+---------+
57+
58+ Atomicity guarantee reverting database to an old state, in case any statement
59+ fails.
2060
2161Consistency
2262===========
0 commit comments