SQL Server中手动给指定表添加表锁

发布于 2024-09-07 09:29:43 字数 168 浏览 11 评论 0原文

我想插入到一个表中,但阻止插入到另一个表中。例如,可以锁定表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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

怪我闹别瞎闹 2024-09-14 09:29:43

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文