How to explicitly lock a table in Microsoft SQL Server (looking for a hack - uncooperative client)

后端 未结 3 837
礼貌的吻别
礼貌的吻别 2021-01-05 00:38

This was my original question:

I am trying to figure out how to enforce EXCLUSIVE table locks in SQL Server. I need to work around uncooperative readers (beyond m

3条回答
  •  孤街浪徒
    2021-01-05 00:42

    Add a locking hint to your SELECT:

    SELECT COUNT(*) FROM artist WITH (TABLOCKX)

    and put your INSERT into a transaction.

    If your initial statement is in an explicit transaction, the SELECT will wait for a lock before it processes.

提交回复
热议问题