Transactions: all or nothing
A transaction groups changes. BEGIN starts it, COMMIT keeps them and ROLLBACK undoes uncommitted changes. Atomicity helps avoid half-finished updates. Transaction behavior and isolation differ by database.
हिन्दी में समझें
ट्रांजैक्शन बदलावों का समूह है। BEGIN शुरू, COMMIT सुरक्षित और ROLLBACK अधूरे बदलाव वापस करता है। इससे आधा-अधूरा अपडेट नहीं रहता।
अभ्यास: BEGIN में product 2 price को 1 करें, फिर ROLLBACK। product 2 का id, price दिखाएँ।
Hinglish mein samjhein
Transaction changes ka group hai. BEGIN start, COMMIT keep, ROLLBACK uncommitted changes undo karta hai. Atomicity half-finished updates se bachati hai.
Practice: BEGIN mein product 2 price 1 karo phir ROLLBACK. Product2 id,price dikhao.
A small SQL example
BEGIN;
UPDATE products SET price=999 WHERE id=1;
ROLLBACK;
SELECT price FROM products WHERE id=1;Examples use the fictional shop database bundled with the SQL playground: customers, products, orders, order_items and employees. The engine is SQLite; other SQL dialects may differ.
Try this example in the SQL playground →Practise this idea
Within BEGIN, change product 2 price to 1, then ROLLBACK. Show id and price for product 2.
Check answer & explanation
BEGIN; UPDATE products SET price=1 WHERE id=2; ROLLBACK; SELECT id,price FROM products WHERE id=2;ROLLBACK discards the uncommitted price change. Selecting product 2 afterward therefore shows its original price of 400.
Stuck in the course? Choose Check answer for either the challenge or quiz. Read the explanation and continue to the next lesson at your own pace.
Check your understanding
Which keeps transaction changes?
Check the quiz answer
COMMIT
A transaction groups changes. BEGIN starts it, COMMIT keeps them and ROLLBACK undoes uncommitted changes. Atomicity helps avoid half-finished updates. Transaction behavior and isolation differ by database.
References & corrections
Use the official SQLite documentation for full language rules. Read how these lessons are made and checked. Found a mistake? Report it to Excel Keys with this lesson URL and a reproducible example.