If you do
BEGIN TRANSACTION UPDATE accounts set balance = balance - amount WHERE ac_num = 101 UPDATE accounts set balance = balance + amount WHERE ac_num = 102 COMMIT TRANSACTION
The database system will write notes about what has been done to change account 101. And then, if work on account 102 fails, the RDBMS uses these notes to cancel work on 101.
In addition, when he started working on account 101, a database lock occurs, so no one can come in and read the updated but not fixed data in account 101. (The lock here is basically just a note somewhere "I work here don't touch. ")
source share