SQL Server 中的服务器端 NOLOCK

发布于 2024-09-14 11:41:03 字数 91 浏览 3 评论 0 原文

我知道在 Oracle DB 中我可以配置一个标志,在特定数据库上运行的所有选择查询都可以像添加了 NOLOCK 提示一样运行。 SQL Server中有类似的东西吗?

I know that in the Oracle DB I can configure a flag, that all select queries running on a specific DB can be run as if the NOLOCK hint was added.
Is there something similar in SQL Server?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

盛夏已如深秋| 2024-09-21 11:41:03

您可以将数据库设置为 READ_ONLY 模式,这肯定会改变一些事务规则,但我不认为有什么更接近全局 NOLOCK。

编辑

如果您希望能够执行 DELETE、INSERT 和 UPDATE,但不希望读取器锁定或必须指定提示或隔离级别,您还可以考虑打开 READ_COMMITTED_SNAPSHOT,但其中的语义又与 NOLOCK 提示不太一样。

You can set the database into READ_ONLY mode, which certainly changes some of the transaction rules, but I don't think there's anything closer to a global NOLOCK.

Edit

If you want to be able to perform DELETEs, INSERTs and UPDATEs, but you don't want readers to lock or have to specify hints or isolation levels, you could also consider turning on READ_COMMITTED_SNAPSHOT, but the semantics there are again not quite the same as the NOLOCK hint.

梦屿孤独相伴 2024-09-21 11:41:03

不是在每个数据库级别。您只能通过提示或设置事务隔离级别来完成此操作。您可以将数据库设置为只读模式,默认情况下可能会产生这种效果,但会(顾名思义)阻止对数据库的写入。

这对于定期刷新的数据库可能很有用。您将数据库设置为只读,并将其设置为可写以进行更新,然后返回只读。

Not at a per-database level. You can only do it with hints or set transaction isolation level. You can set a database to read-only mode, which may have that effect by default but which will (as the name suggests) preclude writes to the database.

This might be useful for a database that is periodically refreshed. You set the database to read-only and set it to writeable for the updates then back to read-only.

在梵高的星空下 2024-09-21 11:41:03

不是针对整个数据库,而是针对您执行的每个查询:

SELECT a, b
FROM t1
WITH (NOLOCK)
WHERE t1.c = @value

SELECT a, b
JOIN t1
ON t1.id = t2.id
WITH (NOLOCK)
FROM t2
WHERE t2.c = @value

Not for the whole database but for each query you do:

SELECT a, b
FROM t1
WITH (NOLOCK)
WHERE t1.c = @value

or

SELECT a, b
JOIN t1
ON t1.id = t2.id
WITH (NOLOCK)
FROM t2
WHERE t2.c = @value

etc

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