A transaction is a group of commands, such that either all of them are executed, or none of them are. For databases that support transactions, the Python interface silently starts a transaction when the cursor is created. Each method then starts a new transaction. Some databases don't have transactions, but simply apply all changes as they're executed. Listing 2 is a Python function tries to get all this right by committing the transaction once both operations have been performed.
Database programming can be potentially quite complex.