ROLLBACK TRANSACTION
rollback
What changes
- Input
- open transaction or savepoint
- Output or change
- undoes changes to the start or savepoint
Syntax at a glance
ROLLBACK { TRAN | TRANSACTION } [ transaction_name | @tran_name_variable | savepoint_name | @savepoint_variable ] [ ; ]
Work example
A validation fails before the transaction should become permanent.
Route the failure to rollback and preserve the original error. Check how savepoints and nested transaction counts behave.
Check your work The write raises the points to 12. The final read after rollback shows the original 5.
Practice SQL
Open in SQL FlowCREATE TABLE #RollbackLab (Points int);
INSERT INTO #RollbackLab VALUES (5);
BEGIN TRANSACTION;
UPDATE #RollbackLab SET Points = 12;
ROLLBACK TRANSACTION;
SELECT Points FROM #RollbackLab;
DROP TABLE #RollbackLab;
Open Microsoft Learn for full syntax, permissions, and details for your version.