Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. SQL Server Difference among ROWLOCK ,UPDLock AND xlock

SQL Server Difference among ROWLOCK ,UPDLock AND xlock

Scheduled Pinned Locked Moved Database
questiondatabasesql-serversysadmintutorial
4 Posts 3 Posters 4 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mou_kol
    wrote on last edited by
    #1

    I have some confusion about lock (ROWLOCK ,UPDLock AND xlock). i want to know the difference among these locks. where to use UPDLock, when to use RowLock and when Xlock with a example for better clarification. 1)

    BEGIN TRANSACTION

    SELECT @ID=RowID FROM MyTable WITH (ROWLOCK, XLOCK, HOLDLOCK) WHERE ID=6822

    In the above sql rowlock and XLOCK both use as a result from other session records 6822 could not be read or modify. XLOCK alone is capable to lock the rows....so why one should use ROWLOCK & XLOCK together ? if i use only xlock & HOLDLOCK then it will not serve the purpose ? 2) Tell me with example what is the difference between ROWLOCK & UPDLOCK ? ROWLOCK prevent other session to modify data and UPDLOCK does the same thing. so what is the difference between ROWLOCK & UPDLOCK ? Please anyone explain these difference with example as a result at my end i can run the example code and understand. Thanks

    Richard DeemingR 1 Reply Last reply
    0
    • M Mou_kol

      I have some confusion about lock (ROWLOCK ,UPDLock AND xlock). i want to know the difference among these locks. where to use UPDLock, when to use RowLock and when Xlock with a example for better clarification. 1)

      BEGIN TRANSACTION

      SELECT @ID=RowID FROM MyTable WITH (ROWLOCK, XLOCK, HOLDLOCK) WHERE ID=6822

      In the above sql rowlock and XLOCK both use as a result from other session records 6822 could not be read or modify. XLOCK alone is capable to lock the rows....so why one should use ROWLOCK & XLOCK together ? if i use only xlock & HOLDLOCK then it will not serve the purpose ? 2) Tell me with example what is the difference between ROWLOCK & UPDLOCK ? ROWLOCK prevent other session to modify data and UPDLOCK does the same thing. so what is the difference between ROWLOCK & UPDLOCK ? Please anyone explain these difference with example as a result at my end i can run the example code and understand. Thanks

      Richard DeemingR Offline
      Richard DeemingR Offline
      Richard Deeming
      wrote on last edited by
      #2

      What is the difference between ROWLOCK, UPDLOCK and HOLDLOCK - Microsoft Q&A[^] There is also information in the Microsoft docs: Table Hints (Transact-SQL) - SQL Server | Microsoft Docs[^]


      "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

      "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

      M 1 Reply Last reply
      0
      • Richard DeemingR Richard Deeming

        What is the difference between ROWLOCK, UPDLOCK and HOLDLOCK - Microsoft Q&A[^] There is also information in the Microsoft docs: Table Hints (Transact-SQL) - SQL Server | Microsoft Docs[^]


        "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

        M Offline
        M Offline
        Mou_kol
        wrote on last edited by
        #3

        Sir Thanks for your reply & link. i read about ROWLOCK & UPDLock but still not clear. they wrote very briefly. if possible sir please discuss the difference between ROWLOCK & UPDLock hint with example. Thanks

        L 1 Reply Last reply
        0
        • M Mou_kol

          Sir Thanks for your reply & link. i read about ROWLOCK & UPDLock but still not clear. they wrote very briefly. if possible sir please discuss the difference between ROWLOCK & UPDLock hint with example. Thanks

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Mou_kol wrote:

          i read about ROWLOCK & UPDLock but still not clear

          MSDN pretty clear.

          Bastard Programmer from Hell :suss: "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups