Simple transaction question

  • Hi-

    I have an OK understanding of the various ISOLATION levels in SQL Server. However, I do have a question.

    What's the difference between these 2 Stored Procedure statements.

    SET ISOLATION LEVEL SERIALIZEABLE

    UPDATE MyTable Set Column1 = 'Updated'

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

    SET ISOLATION LEVEL SERIALIZEABLE

    BEGIN TRANSACTION

    UPDATE MyTable Set Column1 = 'Updated'

    COMMIT TRANSACTION

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

    Essentially, do I need to explicitly begin and commit transactions once I've set the isolation level?

    Thanks - B

  • In this case, nothing, because in the first the UPDATE statement is a transaction itself.

    No, you only need explicit begin and commit if you have a mult-statement "unit of work"

    Eg

    SET XACTABORT ON

    BEGIN TRAN

    IF (SELECT Balance FROM CurrentAccount) >= xferamount

    BEGIN

    UPDATE CurrentAccount Set Balance = Balance - @xferamount

    UPDATE SavingsAccount Set Balance = Balance + @xferamount

    END

    COMMIT TRAN

    Incresing isolation level here will prevent all reads until the entire statement has ran

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

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