MySQL + SQL · Lesson 81

MySQL में Transactions

Transaction क्या है?

Transaction SQL statements का समूह है जिसे एक UNIT माना जाता है — या तो सब सफल (COMMIT) या कोई नहीं (ROLLBACK)। यह multi-step operations में data सुरक्षित रखता है।

Bank Transfer Example

START TRANSACTION;
UPDATE accounts SET balance = balance - 500 WHERE id = 1;
UPDATE accounts SET balance = balance + 500 WHERE id = 2;
COMMIT;   -- दोनों updates साथ save
दूसरा update fail होता तो ROLLBACK पहले को undo कर देता — पैसा कभी नहीं खोता।

मुख्य Commands

  • START TRANSACTION — शुरू।
  • COMMIT — सारे changes save।
  • ROLLBACK — सारे changes undo।

सारांश

  • Transaction statements को एक all-or-nothing unit में बाँधता है।
  • COMMIT save करता है; ROLLBACK undo। Money/critical updates के लिए ज़रूरी।
🔗

Share this topic with a friend

यह topic किसी दोस्त को भेजें

Found it useful? Send it to a classmate learning the same thing.

अच्छा लगा? जो दोस्त यही सीख रहा है, उसे भेज दीजिए।