嵌套事务无法回滚

Nested transaction can't be rolled back

我有 SQL Server 2008 并想进行这样的交易:

begin transaction oo;

......

begin try        
    save transaction xx;
    alter table ....; -- this will fail
    alter table ....;
    alter table ....;
end try
begin catch  
    rollback transaction xx; -- error here
end catch;

......

commit transaction oo;

rollback transaction xx;,我收到消息

3931 The current transaction cannot be committed and cannot be rolled back to a savepoint. Roll back the entire transaction.

我做错了什么?

更新 场景说明:

Reference

你必须在 CATCH 块中使用这一行

ROLLBACK TRANSACTION; 

这将回滚所有事务, 当你在上面的声明中使用这个(在 Q 中发布)时,它会 给我们错误

The COMMIT TRANSACTION request has no corresponding BEGIN TRANSACTION.

为此,您必须将此行放在 TRY 块中

COMMIT TRANSACTION oo;

然后你终于这样说了

BEGIN TRANSACTION oo;

BEGIN TRY        
    SAVE TRANSACTION xx;
    CREATE TABLE test (ID INT); -- this will fail from second time
    SELECT 3;

    COMMIT TRANSACTION oo;
END TRY

BEGIN catch  

    ROLLBACK TRANSACTION; 
END CATCH;

更新 评论后

BEGIN TRY        
    BEGIN TRANSACTION xx1;
    select 1; -- this will always success
    COMMIT TRANSACTION xx1;

    BEGIN TRANSACTION xx2;
    CREATE TABLE test (id int); -- this will fail from second time
    COMMIT TRANSACTION xx2;

    BEGIN TRANSACTION xx3;
    select 3; -- this will fail from second time
    COMMIT TRANSACTION xx3;


END TRY

BEGIN catch  

    ROLLBACK TRANSACTION 
END CATCH;