# Transactions — MySQL Fundamentals: SQL, Joins and Transactions

Source: https://www.skillbyai.com/en/mysql/sql-transactions

> Keep multi-step changes consistent with ACID transactions using START TRANSACTION, COMMIT and ROLLBACK.

## ACID, briefly

**ACID** — Atomicity, Consistency, Isolation, Durability — describes the guarantees a transaction gives you.

## BEGIN, COMMIT, ROLLBACK

Wrap related statements between `START TRANSACTION` and `COMMIT`; `ROLLBACK` undoes everything since the start if something goes wrong.

```sql
START TRANSACTION;
UPDATE accounts SET balance = balance - 500 WHERE id = 1;
UPDATE accounts SET balance = balance + 500 WHERE id = 2;
COMMIT;
```

## Why it matters

Without a transaction, a crash between the two `UPDATE`s above would leave money **deducted from one account but never added to the other**.
