A rollback after an insert that contains an output statement fails with
“The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION.”
If the output statement is removed, then it works. Is there an explanation for this behavior?
Example:
create table test(i integer primary key)
go
begin transaction
insert into test (i) values (1)
insert into test (i) output inserted.i values (1)
go
rollback -- Fails
go
begin transaction
insert into test (i) values (1)
insert into test (i) values (1)
go
rollback -- Works
go
I don’t know why this happens. It looks like SET XACT_ABORT ON is being set implicitly
As a workaround on SQL Server 2005 SP3 we can do this if it’s blocking you
Edit: It could be that the OUTPUT clause is undefined