-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path39_Savepoint.sql
More file actions
30 lines (19 loc) · 860 Bytes
/
39_Savepoint.sql
File metadata and controls
30 lines (19 loc) · 860 Bytes
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
-- SavePoint -> This allows you to set a point within a transaction to which you can later roll back if needed.
-- This is useful for managing complex transactions where you may want to undo certain parts without rolling back the entire transaction.
-- A SAVEPOINT allows you to undo only the last part of a transaction, not the entire transaction.
-- full example:
-- step 1: Begin transaction
START TRANSACTION;
-- Step 2: Insert some data
INSERT INTO alumini (name, company) VALUES ("Rohit", "Amazon");
-- Step 3: Create savepoint
SAVEPOINT sp1;
-- Step 4: Do more operations
INSERT INTO alumini (name, company) VALUES ("Sneha", "Microsoft");
-- Step 5: Rollback only the last insert
ROLLBACK TO SAVEPOINT sp1;
-- Step 6: Commit the transaction
COMMIT;
SELECT * FROM alumini;
-- RELEASE SAVEPOINT -> Deletes the savepoint.
RELEASE SAVEPOINT sp1;