Advance Topics, Transactions (Part 1 of 2)
A transaction is a sequence of one or more SQL statements that are to be executed together as a group. If any part of the transaction’s statements fails, then all actions taken by the statements within the transaction must be reversed. It is an all-or-nothing requirement.If all statements in a single transaction are successful, then all actions taken are made permanent with a COMMIT command. On the other hand, if any of the statements within a transaction fail, then all actions must be reversed with a ROLLBACK command.
An example of a transaction in accounting would be a set of debit and credit entries where the amount of the debit entry exactly matches the amount of the credit entry.
It is your responsability to start and end a transaction at a point that creates a logical transaction. It should be as small as possible while maintaining a logical unit.
See the following EXAMPLEs.