Transactions
Group writes so they succeed or fail together, and choose the right isolation.
What you will be able to do
- Use START TRANSACTION and COMMIT.
- ROLLBACK on error.
- Keep transactions short to reduce lock contention.
- Retry deadlocks with backoff.
In plain English
A transaction is an atomic unit of work. InnoDB gives you ACID guarantees. Use transactions for multi-step writes, keep them short, and handle deadlocks by retrying the whole transaction.
START TRANSACTION;
UPDATE accounts SET balance = balance - 100 WHERE id = 1;
UPDATE accounts SET balance = balance + 100 WHERE id = 2;
COMMIT;Your turn
EasyWrap two updates
Write a transaction that updates two rows and commits.
SQL · starter
START TRANSACTION;Check your understanding before moving on.
Knowledge checkQuestion 1
Which statement makes a transaction’s changes permanent?
Select an answer to continue
Study tools
Make it yours.
Keep a private note for this lesson, then turn the key ideas into flashcards you can revisit.
Sign in to save notes and flashcards.Both are private to your account and stay with your progress.
Sign inFinished reading?
Lock in what you just learned.
0%
Mark this lesson complete to save your place and move one step closer to the certificate.