Isolation level serializable

  • Can someone explain isolation level serializable?

    if two processes run the same stored proc,

    Set transaction isolation level serializable

    begin tran

    declare @currentnum int

    Select @currentnum = currentnum from refnumbers where id = 1;

    update refnumbers set currentnum =

    @currentnum where id = 1;

    commit tran

    so if user1 and user2 run the select query at the same time, does it mean user2 will not be able to select anything until user1 transaction commits? keep in mind user1 has not ran the update yet, both users are running select.

    Can you also explain how serializable level eliminates lost updates?

  • yes

  • If both users will run the select statement at the exact same time, then you’ll have a deadlock. When you work with serializable isolation level, the shared locks that were acquired by both processes will be held until the end of the transactions. Since both processes will next try to update the table, each one of them will have to wait for the other process to release the shared lock. This will cause a deadlock and one of the transactions will be rolled back.

    Adi

    --------------------------------------------------------------
    To know how to ask questions and increase the chances of getting asnwers:
    http://www.sqlservercentral.com/articles/Best+Practices/61537/

    For better answers on performance questions, click on the following...
    http://www.sqlservercentral.com/articles/SQLServerCentral/66909/

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

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