I'm trying to use a Nested Transaction on SQL Server.
Here is my test table
CREATE TABLE [dbo].[Table2] (
[Id] INT NOT NULL
);
And my query
BEGIN TRANSACTION masterTransaction
BEGIN TRANSACTION test
GO
INSERT INTO [dbo].[Table2] VALUES (200)
INSERT INTO [dbo].[Table2] VALUES (201)
COMMIT TRANSACTION test
BEGIN TRANSACTION test2
GO
INSERT INTO [dbo].[Table2] VALUES (202)
INSERT INTO [dbo].[Table2] VALUES (203)
COMMIT TRANSACTION test2
-- Everything before that must be commited
BEGIN TRANSACTION test3
GO
INSERT INTO [dbo].[Table2] VALUES (204)
INSERT INTO [dbo].[Table2] VALUES (205)
ROLLBACK TRANSACTION test3
COMMIT TRANSACTION masterTransaction
My goal it's to have a main transaction and micro transactions inside that. If the user ask to abort, my masterTransaction will rollback all data inside. But the user have the option to abort and discard only the last transaction.
My error: Test3 can not be rolled back. No save or transaction point was found under this name.
What am I doing wrong?