COMMIT TRANSACTION
commit
What changes
- Input
- open transaction
- Output or change
- makes changes durable when @@TRANCOUNT reaches 0
Syntax at a glance
COMMIT [ { TRAN | TRANSACTION } [ transaction_name | @tran_name_variable ] ] [ WITH ( DELAYED_DURABILITY = { OFF | ON } ) ] [ ; ]
Work example
All required work in the current transaction has passed its checks and can become permanent.
Commit only after every required statement succeeds. Confirm the transaction nesting count before and after.
Check your work The temporary table still contains 8 points after commit. OpenCount is zero.
Practice SQL
Open in SQL FlowCREATE TABLE #CommitLab (Points int);
BEGIN TRANSACTION;
INSERT INTO #CommitLab VALUES (8);
COMMIT TRANSACTION;
SELECT Points, @@TRANCOUNT AS OpenCount FROM #CommitLab;
DROP TABLE #CommitLab;
Open Microsoft Learn for full syntax, permissions, and details for your version.