SQL Server中手动给指定表添加表锁
我想插入到一个表中,但阻止插入到另一个表中。例如,可以锁定表a进行插入,插入表b,然后解锁表a?
TABLOCK 只能锁定我正在插入的表。
谢谢
Martin Pilch
I want to INSERT into one tables but prevent INSERTING to another one. It is possible to LOCK for example table a for INSERTING, INSERT to table b and then UNLOCK table a?
TABLOCK can lock only the table I am INSERTING in.
Thanks
Martin Pilch
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
SQL Server 不允许像信号量那样锁定对象。此外,锁定表不会使其变为只读;这将使每个人都被锁定。
您可以使用表提示(例如
SELECT * FROM MyTable WITH (LOCKNAME)
)来放置锁,但这不是一个好的编程实践。SQL Server does not allow locking objects like you would do semaphors. Also, locking a table will not make it read-only; it will make it locked out for everybody.
You can place a lock by using a table hint such as
SELECT * FROM MyTable WITH (LOCKNAME)
but that is not a good programming practice.