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. Dead lock issue with Update and delete statement on the same table

Dead lock issue with Update and delete statement on the same table

Scheduled Pinned Locked Moved Database
helpannouncement
3 Posts 2 Posters 0 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.
  • K Offline
    K Offline
    kali siddhu
    wrote on last edited by
    #1

    I am getting dead lock issue due to below transaction. Please could you help on this.

    ------------------------------------------------------Transaction 1------------------------------------------------------
    Transactionname="DELETE"
    waitresource="KEY: 6:72057594046054400 (6a6c767d8e74)"
    lasttranstarted="2020-07-11T05:48:38.007"
    lockMode="U"
    isolationlevel="read committed (2)"
    status="suspended"

    DELETE FROM [Channel] WHERE FileInventoryKey IN (SELECT FileInventoryKey FROM #FileInventoryKeys)

    --------------------------------------------------------Transaction 2------------------------------------------------------
    Transactionname="UPDATE"
    waitresource="KEY: 6:72057594046054400 (93201dea6b78)"
    lasttranstarted="2020-07-11T05:48:38.007"
    lockMode="U"
    isolationlevel="read committed (2)"
    status="suspended"

    update ch set ChannelKey = c.ChannelKey
    from Channel ch
    join ChannelVersion c on c.ChannelID = ch.ChannelID
    join Channel cc on cc.ChannelKey = c.ChannelKey and (cc.HasIntervalData = 0 and ch.IsRegister = 'true') --register channels where c.ChannelVersionKey in (select ChannelVersionKey from [#UpdatedChannels]

    I have two options 1). UPD lock on the update statement 2). SET TRANSACTION ISOLATION LEVEL Snapshot

    D 1 Reply Last reply
    0
    • K kali siddhu

      I am getting dead lock issue due to below transaction. Please could you help on this.

      ------------------------------------------------------Transaction 1------------------------------------------------------
      Transactionname="DELETE"
      waitresource="KEY: 6:72057594046054400 (6a6c767d8e74)"
      lasttranstarted="2020-07-11T05:48:38.007"
      lockMode="U"
      isolationlevel="read committed (2)"
      status="suspended"

      DELETE FROM [Channel] WHERE FileInventoryKey IN (SELECT FileInventoryKey FROM #FileInventoryKeys)

      --------------------------------------------------------Transaction 2------------------------------------------------------
      Transactionname="UPDATE"
      waitresource="KEY: 6:72057594046054400 (93201dea6b78)"
      lasttranstarted="2020-07-11T05:48:38.007"
      lockMode="U"
      isolationlevel="read committed (2)"
      status="suspended"

      update ch set ChannelKey = c.ChannelKey
      from Channel ch
      join ChannelVersion c on c.ChannelID = ch.ChannelID
      join Channel cc on cc.ChannelKey = c.ChannelKey and (cc.HasIntervalData = 0 and ch.IsRegister = 'true') --register channels where c.ChannelVersionKey in (select ChannelVersionKey from [#UpdatedChannels]

      I have two options 1). UPD lock on the update statement 2). SET TRANSACTION ISOLATION LEVEL Snapshot

      D Offline
      D Offline
      David Mujica
      wrote on last edited by
      #2

      If you are using SQL server and the DELETE operation can be delayed or postponed try this approach … Use an application lock to synchronize two different processes that data is being manipulated and try again later ... Microsoft has sp_getapplock Maybe it would work for you.

      K 1 Reply Last reply
      0
      • D David Mujica

        If you are using SQL server and the DELETE operation can be delayed or postponed try this approach … Use an application lock to synchronize two different processes that data is being manipulated and try again later ... Microsoft has sp_getapplock Maybe it would work for you.

        K Offline
        K Offline
        kali siddhu
        wrote on last edited by
        #3

        These are three solutions which one will be the best one and let me know if i need to change anything in the solution. First solution : EXEC @returnCode = Sp_getapplock @Resource = 'Resource_stg_SqlQueueManager', @LockMode = 'Exclusive', @LockOwner = 'Transaction ', @LockTimeout = 500000 Second solution SET TRANSACTION ISOLATION LEVEL SNAPSHOT Third solution Update with nolock Example : update ch set ChannelKey = c.ChannelKey from CRF_Channel ch with (nolock) join ChannelVersion c on c.ChannelID = ch.ChannelID join Channel cc on cc.ChannelKey = c.ChannelKey and (cc.HasIntervalData = 0 and ch.IsRegister = 'true')

        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