PGoCareerGoCareer prep tools
LoginSign up
  • Java
  • Python
  • AI
  • React
  • Angular
  • PHP
  • Node.js
  • SQL
  • DSA
  • HTML
  • CSS
  • JS
  • Spring
  • ML
  • MongoDB

SQL · Theory

Transaction

← All stacks

Theory

286/439

Transaction

A transaction is a group of statements that all succeed or all fail. Fee payment: subtract wallet, insert receipt. START TRANSACTION; UPDATE …; INSERT …; COMMIT; If the insert fails, ROLLBACK; — wallet should not stay subtracted.

ACID: Atomic (all or nothing), Consistent (rules kept), Isolated (other sessions don’t see half-work), Durable (after COMMIT, it survives a crash). InnoDB supports this. MyISAM does not.

autocommit is ON by default — each statement is its own transaction. START TRANSACTION (or BEGIN) turns a batch into one unit. COMMIT ends it. ROLLBACK undoes since START.

Trap — no transaction around two related writes. Trap: COMMIT after an error you did not notice.

On the example next to this theory: Transaction: create two demo rows, then SELECT qty >= 2 ordered. Say which labels come back.

Diagram
START TRANSACTION
     UPDATE wallet
     INSERT receipt
        │
        ├── COMMIT   → both kept
        └── ROLLBACK → both undone
Exam tip

START TRANSACTION; two writes; COMMIT; or ROLLBACK;

Transaction — sample query

-- Transaction
CREATE TABLE demo (
  id INTEGER PRIMARY KEY,
  label TEXT NOT NULL,
  qty INTEGER DEFAULT 0
);
INSERT INTO demo (id, label, qty) VALUES
  (1, 'alpha', 2),
  (2, 'beta', 5);
SELECT label, qty FROM demo WHERE qty >= 2 ORDER BY qty DESC;

Transaction: create two demo rows, then SELECT qty >= 2 ordered. Say which labels come back.

Short notes

  • DefTransaction = all statements commit or all rollback.
  • RuleInnoDB. START TRANSACTION … COMMIT / ROLLBACK.
  • TrapMyISAM. Two writes without a transaction.

Questions

1

What is COMMIT?

2

What is ROLLBACK?

3

Why InnoDB?

286 / 439

P

GoCareerGo

Utilities · Preparation Hub · Resume · CV · Tools — one workspace.

Workspace

DashboardProfilePreparation HubResume builderCV builderCareer planning

PDF Tools

Merge PDFSplit PDFCompress PDFImage to PDFAll toolsJobs

Image & QR

Compress ImageResize ImageQR ScannerQR GeneratorBlogIT interview prep

Company

FAQFeedbackContactPrivacyTermsSitemap

© 2026 GoCareerGo. Keep moving forward.