Skip to content
Learn Netverks

Lesson

Step 28/36 78% through track

transactions-intro

Transactions introduction

Last reviewed May 28, 2026 Content v20260528
Track mode
sql_sandbox
Means
SQL sandbox
Reading
~1 min
Level
advanced

This lesson

An orientation to the SQL track—relational concepts, query patterns, and how to practice until the SQL sandbox lab ships.

You need a clear map of the SQL track so tables, keys, JOINs, and aggregates do not feel like magic.

You will apply Transactions introduction in contexts like: Checkout flows, ledger transfers, and inventory updates that must be all-or-nothing.

Copy SQL from each lesson into SQLite (sqlite3), DB Fiddle, or local Postgres—read result grids and row counts. The in-browser SQL lab (sql_sandbox) will run queries when the runner ships; until then, local clients are the practice path. Also read the interview prep blocks.

After basic programming literacy—before ORM-heavy frameworks assume you can read the SQL they generate.

A transaction groups statements into one atomic unit—ACID guarantees prevent partial updates when transferring money, reserving inventory, or syncing related rows.

BEGIN / COMMIT

BEGIN TRANSACTION;

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

COMMIT;

Practice: Advanced features vary by engine—SQLite 3.25+ supports window functions; test your version with a simple query.

SQLite defaults to autocommit; explicit BEGIN starts a transaction block.

ROLLBACK

BEGIN;
DELETE FROM orders WHERE id = 999;
-- Oops wrong id
ROLLBACK;

ROLLBACK undoes changes since BEGIN. Production apps use transactions around related DML in Django atomic() blocks and PDO transactions in PHP.

ACID recap

  • Atomicity — all or nothing
  • Consistency — constraints hold after commit
  • Isolation — concurrent sessions see controlled visibility
  • Durability — committed data survives crashes

Important interview questions and answers

  1. Q: Why transactions for transfers?
    A: Debit and credit must succeed together—partial update corrupts balances.
  2. Q: Autocommit?
    A: Each statement commits alone unless wrapped in explicit transaction.

Self-check

  1. Which keyword undoes a transaction?
  2. Name two ACID properties.

Tip: Wrap related DML in transactions—Django atomic() and PDO transactions do the same.

Interview prep

ACID atomicity?

All statements commit together or none do.

ROLLBACK?

Undoes changes since BEGIN.

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • ACID meaning?
  • Isolation levels?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump