BolEnglishLearn · Play · Win
Login

🔁 Data & Database Design · Data & Databases

🔁

Transactions

Data ConceptAdvancedModule 4

Group related database changes so they succeed or fail together.

Partial updates can create invalid data.

💡 In practice

Creating an order and its required items rolls back if a critical save fails.

🖼️ CONCEPT PICTURE
A picture to help remember Transactions
Creating an order and its required items rolls back if a critical save fails.

💡 Like a bank transfer: the money must leave one account and arrive in the other as one move — never vanish halfway.

💡 Learn🛠️ Apply🎯 Check

💡 Why it matters

Many business actions touch several rows that must all change or none at all. A transaction wraps them so a crash or error cannot leave half-finished, invalid data behind. This all-or-nothing guarantee is what keeps the database trustworthy under failures and concurrent use.

🛠️ How to achieve it

1
Wrap related changes
Put the changes that must stay consistent inside one transaction, like an order plus its items.
2
Commit or roll back
If every step succeeds, commit. If any critical step fails, roll back so nothing partial remains.
3
Keep transactions short
Do only the necessary writes inside; long transactions block others and risk timeouts.
4
Handle conflicts
Plan for two transactions touching the same rows, and retry safely where appropriate.

⚠️ Signs of trouble

  • •A failed operation leaves half the data saved.
  • •Totals or balances sometimes do not add up.
  • •Long-running transactions block other users.
  • •Related rows exist without their partners.
⚠️ Common mistake: Saving related records one by one with no transaction, so a mid-way failure leaves inconsistent data. Wrap the group in a single transaction that commits or rolls back as a whole.

🎯 Quick check

Score: 0/3

Three questions to test the idea.

  1. 1. What does a transaction guarantee?

    Answer: Grouped changes all succeed or all fail together

    A transaction is all-or-nothing: either every change commits, or they all roll back, so no partial data survives.

  2. 2. An order saves but its required items fail. With a transaction, what happens?

    Answer: The whole thing rolls back, leaving no partial order

    Because the writes are in one transaction, a failed step rolls everything back — no half-saved order remains.

  3. 3. Why keep transactions short?

    Answer: Long ones block other users and risk timeouts

    A transaction holds locks until it finishes, so a long one makes others wait and can time out.

🔑 Key terms

Commit
Make all the transaction's changes permanent.
Rollback
Undo every change in the transaction.
Atomicity
All steps happen, or none do.
Deadlock
Two transactions each waiting on the other, stuck forever.

✅ Review checklist

📊 Your progress

0%
Mark this topic learned to track it.
Saved in this browser.
🚀 Got it?
Mark it learned and move to the next topic.
Next topic →