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

后端 未结 3 838
礼貌的吻别
礼貌的吻别 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 01:01

    One hack hack hack way to do this is to force an operation on the table which takes a SCH-M lock on the table, which will prevent reads against the table even in READ UNCOMMITTED isolation level. Eg, doing an operation like ALTER TABLE REBUILD (perhaps on a specific empty partition to reduce performance impact) as part of your operation will prevent all concurrent access to the table until you commit.

提交回复
热议问题