SQL Server ROWLOCK over a SELECT if not exists INSERT transaction

后端 未结 1 1072
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-02 20:52

I have upgraded from SQL Server 2005 to 2008. I remember that in 2005, ROWLOCK simply did not work and I had to use PAGELOCK or XLOCK to achieve any type of actual locking.

相关标签:
1条回答
  • 2021-01-02 21:29

    An explanation...

    • ROWLOCK/PAGELOCK is granularity
    • XLOCK is mode

    Granularity and isolation level and mode are orthogonal.

    • Granularity = what is locked = row, page, table (PAGLOCK, ROWLOCK, TABLOCK)

    • Isolation Level = lock duration, concurrency (HOLDLOCK, READCOMMITTED, REPEATABLEREAD, SERIALIZABLE)

    • Mode = sharing/exclusivity (UPDLOCK, XLOCK)

    • "combined" eg NOLOCK, TABLOCKX

    XLOCK would have locked the row exclusively as you want. ROWLOCK/PAGELOCK wouldn't have.

    0 讨论(0)
提交回复
热议问题