शब्दकोश · डेटाबेस

Database Transaction

A database transaction groups several operations into one all-or-nothing unit of work, committed together on success or rolled back together on failure.

अपडेट: अक्टूबर 6, 2026

A database transaction is a group of operations treated as a single unit of work. Either every step is committed and becomes permanent, or the whole group is rolled back as if nothing happened.

Why it matters

Transactions keep data consistent when multiple related changes must stay in step, such as creating an order and reducing stock. They also control what concurrent users can see through isolation levels. Long-running transactions hold locks and block others, so keeping them short is a key operational habit.

Example

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

If the second update fails, ROLLBACK restores the first account to its original balance.

Common mistakes

  • Leaving a transaction open while waiting on a user or a slow external API call, which holds locks.
  • Forgetting error handling, so a failed statement leaves the connection in an aborted transaction.
  • Assuming auto-commit is off. Many clients commit each statement immediately by default.

Get notified when this term updates

Plus occasional practical tips on uptime and monitoring, nothing else. Unsubscribe anytime.

यह पेज सामान्य जानकारी है, जिसे हमारी संपादकीय टीम ने लिखा है और दस्तावेज़ीकरण बदलने पर अपडेट किया जाता है। सर्वर और प्रदाता अलग-अलग होते हैं, इसलिए बदलाव पहले सुरक्षित तरीके से जाँचें। देखें: संपादकीय नीति और अस्वीकरण.