forked from sbgowtham/SQL_DataEngineering_MasterClass
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path26.commit_rollback
More file actions
39 lines (24 loc) · 1.17 KB
/
Copy path26.commit_rollback
File metadata and controls
39 lines (24 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
My complete SQL Masterclass Notes in Tanglish is now live! Covers 30+ topics with syntax, examples, and step-by-step explanations.
Perfect for both beginners and professionals to master SQL easily. Check it out here 👉 https://topmate.io/dataengineering/1697791
====================================================================================
Its used for saferside while working in a important database(updation & rollback to before updation).
To use commit & rollback we need to start transaction; first if not the updation will be automatically commited and we cant rollback again.
CREATE TABLE Accounts (
AccountID INT PRIMARY KEY,
AccountHolder VARCHAR(100),
Balance DECIMAL(10,2)
);
-- Insert a new record into Accounts
INSERT INTO Accounts (AccountID, AccountHolder, Balance)
VALUES (1, 'Alice', 5000.00);
START TRANSACTION;
-- Perform one or more SQL statements
UPDATE Accounts SET Balance = Balance - 1000 WHERE AccountID = 1;
select * from accounts;
-- If all statements execute successfully, commit the transaction
COMMIT;
-- or
UPDATE Accounts SET Balance = Balance - 1000 WHERE AccountID = 1;
select * from accounts;
rollback;
select * from accounts;