SAVE TRANSACTION
named savepoint
What changes
- Input
- open transaction
- Output or change
- savepoint marker
Syntax at a glance
SAVE { TRAN | TRANSACTION } { savepoint_name | @savepoint_variable } [ ; ]
Work example
A larger transaction needs a named point for partial rollback without ending the outer transaction.
Use a unique savepoint name and verify the transaction is committable before rolling back to it.
Check your work The read shows 8 points and one open transaction. Only the change after KeepFirst was undone.
Practice SQL
Open in SQL FlowCREATE TABLE #SaveLab (Points int);
INSERT INTO #SaveLab VALUES (5);
BEGIN TRANSACTION;
UPDATE #SaveLab SET Points = 8;
SAVE TRANSACTION KeepFirst;
UPDATE #SaveLab SET Points = 12;
ROLLBACK TRANSACTION KeepFirst;
SELECT Points, @@TRANCOUNT AS OpenCount FROM #SaveLab;
COMMIT TRANSACTION;
DROP TABLE #SaveLab;
Open Microsoft Learn for full syntax, permissions, and details for your version.