π Managing Transactions in Oracle SQL (COMMIT & ROLLBACK Explained with Real Example)

While working with Oracle Autonomous Database, I explored how transactions work and why they are critical in real-world applications like banking systems.
In many systems, multiple operations must either complete successfully together or not at all. This is where transactions ensure data consistency and reliability.
π― Real-World Scenario
Imagine transferring money between two accounts:
Deduct amount from Account A
Add amount to Account B
π If one step fails, the entire operation must be reversed.
This is exactly what transactions solve.
π» Step 1: Creating the Table
CREATE TABLE accounts (
acc_id NUMBER,
acc_name VARCHAR2(50),
balance NUMBER
);
π§ͺ Step 2: Inserting Initial Data
INSERT INTO accounts VALUES (1, 'Ali', 10000);
INSERT INTO accounts VALUES (2, 'Sara', 8000);
π Step 3: Performing Transaction (Money Transfer)
UPDATE accounts SET balance = balance - 2000 WHERE acc_id = 1;
UPDATE accounts SET balance = balance + 2000 WHERE acc_id = 2;
π Step 4: Checking Data Before COMMIT
SELECT * FROM accounts;
At this stage, changes are visible but not permanently saved.
β Step 5: Rolling Back Changes
ROLLBACK;
π This cancels all changes and restores original data.
β Step 6: Committing Changes
UPDATE accounts SET balance = balance - 2000 WHERE acc_id = 1;
UPDATE accounts SET balance = balance + 2000 WHERE acc_id = 2;
COMMIT;
π Now changes are permanently saved
π‘ Key Insights
Transactions ensure data consistency
COMMIT saves changes permanently
ROLLBACK cancels changes
Essential for financial and enterprise systems
π§ My Learning Experience
This exercise helped me understand that SQL is not just about queriesβitβs about controlling how data behaves in real systems.
Understanding transactions gave me a deeper insight into how real-world applications maintain reliability.
π Conclusion
Transactions are a fundamental concept in Oracle SQL that ensure safe and reliable database operations. They are widely used in banking, e-commerce, and enterprise systems.




