Confusion in transaction

  • Hi,

    While running this set of statements,

    declare @Amount as int

    set @Amount = 1000

    print @Amount

    begin tran

    set @Amount = @Amount + 1000

    print @Amount

    begin tran

    set @Amount = @Amount + 1000

    print @Amount

    commit tran

    set @Amount = @Amount + 1000

    rollback tran

    print @Amount

    I thought that last statement will rollback the the data and set amount variable to "3000". But its printing "4000"... Will rollback transaction not work for variables?

  • No, variables are not affected by transactions. This is also true of table variables.

  • Just to add to what Lynn has mentioned,

    its a variable stored in memory for our operations, where would it 'commit/rollback' it to (no table or anything to go back to!)?

    ---------------------------------------------------------------------------------

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply