Careeroza
What is a Transaction?
Transactions
A transaction is a group of SQL statements that must succeed or fail together. The classic example is a bank transfer: taking money from one account and adding it to another must both happen, or neither.
TCL (Transaction Control Language) commands control transactions: BEGIN/START TRANSACTION, COMMIT, ROLLBACK and SAVEPOINT.
Life of a Transaction
BEGIN(orSTART TRANSACTION) starts it.- Run one or more
INSERT/UPDATE/DELETEstatements. Other sessions do not see the changes yet. COMMITmakes all changes permanent, orROLLBACKundoes all of them.
Note: Most databases run in auto-commit mode: every statement outside an explicit transaction is committed immediately. Oracle is the exception; there you must COMMIT yourself.