Middle
How to implement partial transaction rollback (not full, but up to a certain point)?.
sobes.tech AI
Answer from AI
Partial rollback of a transaction is implemented using savepoints. A savepoint allows you to set a control point within a transaction to which you can roll back without canceling the entire transaction.
Example in SQL (PostgreSQL):
BEGIN;
-- operation 1
SAVEPOINT sp1;
-- operation 2
-- if you need to rollback only to sp1
ROLLBACK TO SAVEPOINT sp1;
-- continue the transaction
COMMIT;
Thus, you can rollback changes only after the savepoint, preserving previous changes within a single transaction.