Avoiding the transaction

  • Comments posted to this topic are about the item Avoiding the transaction

  • Nice, easy question to start the week on, thanks Steve.

    ____________________________________________
    Space, the final frontier? not any more...
    All limits henceforth are self-imposed.
    β€œlibera tute vulgaris ex”

  • Thanks Steve, good question.

    My take on it is that "begin tran --- rollback" = "Oops"

    😎

    On a more serious note, many do not understand the difference between SET and SELECT in this context, if one changes the code to:

    DECLARE @salary INT = 1000;
    BEGIN TRAN
    SET @salary = @salary * 2;
    ROLLBACK
    SELECT @salary;

    then the result will be 2000, as the SET statement is NOT a part of the transaction, even if it occurs within the BEGIN - END section.

    πŸ˜‰

     

  • This is an illustration, not real code. Presumably, you might have lots of other code that checks for the need to rollback.

    However, I'm not sure SET and SELECT impact the transaction with a local variable. The local variable is outside the tran.

  • Steve Jones - SSC Editor wrote:

    This is an illustration, not real code. Presumably, you might have lots of other code that checks for the need to rollback.

    However, I'm not sure SET and SELECT impact the transaction with a local variable. The local variable is outside the tran.

    Sorry Steve, there is no difference, my mind was somewhere else.

    😎

Viewing 5 posts - 1 through 4 (of 4 total)

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