交易 - 将表可用于其他查询,直到准备提交给它

发布于 2025-02-14 00:28:51 字数 717 浏览 0 评论 0原文

我有一个存储过程,需要一段时间,并重建其他查询用于查找的文件。

因此,我想:

  1. 开始交易
  2. 重建表(需要一段时间)
  3. 在步骤2期间提交交易

,我希望其他无关的查询来读取此表(没有程序内更新。)对我来说,可以看到数据是很好的步骤1开始之前。

显然,我不希望查询等待交易完成。

问题:我需要在交易上指定的参数(例如隔离级别)吗?我需要在选定语句上“用nolock”做?

如果有人可以将我指向正确的方向?很难搜索这个问题。

这是一个模型,我想在存储过程正在运行时查询表IREALLYWANTTOQUERYTHISTAST,并在交易开始之前查看数据:

create procedure bigoldlongprocedure
as
    Begin Tran Doit
        drop table if exists IReallyWantToQueryThisTable
        create table IReallyWantToQueryThisTable
        (Id int
        , dataforme varchar(20)
        )
        -- Takes a long time
        exec dbo.spReLoad_IReallyWantToQueryThisTable
    Commit Tran Doit
Return 0

I have a stored procedure that takes awhile and rebuilds a file that other queries use for lookup.

So i want to:

  1. Begin a transaction
  2. Rebuild a table (takes awhile)
  3. Commit the transaction

During step 2, I want other unrelated queries to read this table (without the in-progress updates.) It's fine for me to see the data that was there before step 1 began.

And obviously, I don't want the query to wait for the transaction to finish.

Question: Are there parameters (like isolation level) that I need to specify on the transaction? Do i need to do "with nolock" on the select statements?

if someone could point me in the right direction? It's been a little hard to search for this.

Here's an mockup where i would want to query table IReallyWantToQueryThisTable while the stored procedure is running and see the data from before the transaction started:

create procedure bigoldlongprocedure
as
    Begin Tran Doit
        drop table if exists IReallyWantToQueryThisTable
        create table IReallyWantToQueryThisTable
        (Id int
        , dataforme varchar(20)
        )
        -- Takes a long time
        exec dbo.spReLoad_IReallyWantToQueryThisTable
    Commit Tran Doit
Return 0

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

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

发布评论

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

评论(1

她说她爱他 2025-02-21 00:28:52

在此交易中,无需为表IREALLYWANTTOWISSISTAISS设置任何可读的隔离水平。
交易的五种隔离水平是
读取不承诺
|读取
|可重复阅读
|快照
|可序列化
该表对于其他tranc是不可读的,就在设置可序列化时。

there is no need to set any readable isolation level for the table IReallyWantToQueryThisTable in this transaction.
five types of isolation level for a transaction are
READ UNCOMMITTED
| READ COMMITTED
| REPEATABLE READ
| SNAPSHOT
| SERIALIZABLE
the table is unreadable for other tranc,just when setting SERIALIZABLE.so just make sure the isolation level in dbo.spreload is not SERIALIZABLE.

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