Master SQL Transactions with Fullstackgadaโs fun approach! ๐๏ธ
| OrderID | Product | Qty | Status |
|---|
| Product | StockLeft |
|---|
BEGIN;
/* Step 1: Reduce stock */
UPDATE Stock SET count = count - 1 WHERE product='Soap';
/* Step 2: Insert order */
INSERT INTO Orders(product, qty, status) VALUES ('Soap', 1, 'Pending');
/* Step 3: Payment */
-- Imagine payment step here
/* All good */
COMMIT;
/* If an error occurs */
ROLLBACK;