How does sql server decides which transaction is first and which one is the last if both happen at the same time

  • I just have a basic question about transaction - If two transactions from different sessions start exactly at the same time, one transaction has to wait till the other finishes. This is one of the ACID properties. Now my question is how will the system decide which transaction is the first one and which one has to wait as both transactions happen at exatly same time.

  • You're going to want to read up on isolation levels:

    https://technet.microsoft.com/en-US/library/ms189122(v=SQL.105).aspx

    ----------------------------------------------------------------------------------
    Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?

  • the chances of them starting at exactly the same time are going to be rare to be frank, whichever process gets the resource first will win the other will wait

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

    "Ya can't make an omelette without breaking just a few eggs" 😉

  • One of the tasks will acquire the lock first, and then the other one will have to wait. SQL's locking mechanism is what it allows it to "sequence" these potentially-conflicting actions.

    SQL DBA,SQL Server MVP(07, 08, 09) "It's a dog-eat-dog world, and I'm wearing Milk-Bone underwear." "Norm", on "Cheers". Also from "Cheers", from "Carla": "You need to know 3 things about Tortelli men: Tortelli men draw women like flies; Tortelli men treat women like flies; Tortelli men's brains are in their flies".

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

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