I Help You
Databases

Database Transaction

A database transaction is a group of one or more SQL operations that is treated as a single unit of work: either all of them succeed together, or none of them take effect. The classic example is a bank transfer, where money is taken from one account and added to another; the database must never save only one half.

A transaction starts with BEGIN (or START TRANSACTION), is saved permanently with COMMIT and is undone with ROLLBACK if anything goes wrong. Transactions follow the ACID properties, and their isolation level decides how much concurrent transactions can see of each other's changes.

ExampleSQL
START TRANSACTION;

UPDATE accounts SET balance = balance - 1000 WHERE id = 1;
UPDATE accounts SET balance = balance + 1000 WHERE id = 2;

COMMIT;   -- or ROLLBACK; to undo both updates