T-SQL Tutorial

T-SQL SAVE Transaction


The SAVE transaction sets a save point within a transaction.

Save transaction syntax:

SAVE { TRAN | TRANSACTION } { savepoint_name | @savepoint_variable } ;

Save transaction example:

USE model;
GO
DECLARE @Counter INT;
SET @Counter = @@TRANCOUNT;
IF @Counter > 0
SAVE TRANSACTION my_savepoint;
ELSE
BEGIN TRANSACTION;
GO
insert into students(id,first_name, last_name, gender,city, country, section)
values(8,'Alysia','MARTIN','F','Toronto','Canada', 'Biology');
GO
COMMIT TRANSACTION;
GO