T-SQL Tutorial

T-SQL COMMIT Transaction


The COMMIT Transaction is the end point of a successful implicit or explicit transaction.
When @@TRANCOUNT is 1, all data modifications performed are commit and the resources held by the transaction are released, and decrements @@TRANCOUNT to 0. When @@TRANCOUNT is greater than 1, COMMIT TRANSACTION decrements @@TRANCOUNT only by 1 and the transaction stays active.

Commit transaction syntax:

COMMIT [ { TRAN | TRANSACTION } [ transaction_name | @transaction_name_variable ] ]
[ WITH ( DELAYED_DURABILITY = { OFF | ON } ) ] ;

Commit transaction example:

USE model;
GO
BEGIN TRANSACTION;
GO
DELETE FROM students WHERE id = 7 and section = 'History';
GO
insert into students(id,first_name, last_name, gender,city, country, section)
values(7,'Ashley','THOMPSON','F','London','Liverpool', 'History');
GO
COMMIT TRANSACTION;
GO