启动多个存储过程以“在后台”运行在 SQL Server Express 版本上

发布于 2024-08-10 14:13:25 字数 364 浏览 7 评论 0原文

是否可以运行多个“在后台”运行的存储过程?

存储过程必须从单个主存储过程启动,就像生成多个工作线程一样。例如:

CREATE PROCEDURE MyLauncher
AS
BEGIN
    BEGIN
      @EXEC MyBackgroundSP01 -- Runs in parallel to the other 2
      @EXEC MyBackgroundSP02 -- Runs in parallel to the other 2
      @EXEC MyBackgroundSP03 -- Runs in parallel to the other 2
    END
END

Is it possible to run multiple stored procedures that run 'in the background'?

The stored procedures must be launched from a single, master stored procedure, in the same way that multiple worker threads are spawned. For example:

CREATE PROCEDURE MyLauncher
AS
BEGIN
    BEGIN
      @EXEC MyBackgroundSP01 -- Runs in parallel to the other 2
      @EXEC MyBackgroundSP02 -- Runs in parallel to the other 2
      @EXEC MyBackgroundSP03 -- Runs in parallel to the other 2
    END
END

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

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

发布评论

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

评论(6

习ぎ惯性依靠 2024-08-17 14:13:25

在 SQL 2005 及更高版本中这是可能的。看看 http://rusanu.com/2009/08/05/异步过程执行/

It is possible in SQL 2005 and later. Have look at http://rusanu.com/2009/08/05/asynchronous-procedure-execution/

友欢 2024-08-17 14:13:25

不,正如您所描述的那样,这是不可能的。您可以运行多个 SQL 作业,这些作业将同时执行过程/

No this isn't possible as you have described it. You could run multiple SQL Jobs which will execute the procedures concurrently/

秋凉 2024-08-17 14:13:25

根据这个问题,您可以尝试使用服务代理

异步存储过程调用

According to this question you could try using the Service Broker

Asynchronous Stored Procedure Calls

心凉怎暖 2024-08-17 14:13:25

如果您在同一过程中运行它们,它将在同一线程中启动(并且在同一内部事务中,这会使日志非常大)。

If you run they in the same procedure, it will launch in the same thread (and in the same internal transaction, what can make the log very big).

放赐 2024-08-17 14:13:25

纯 T-SQL 则不然。但是您可以编写一个小 dotNET 应用程序来足够轻松地异步运行它们,只要保留连接选项直到所有三个都完成即可。

Not with pure T-SQL. But you could write a little dotNET app to run them asynchronously easily enough, as long as you leave the connection option until all three are finished.

一世旳自豪 2024-08-17 14:13:25

如果两个存储过程具有相同的参数,那么您可以创建一个新的存储过程
喜欢的

create third procedure
(@colname int)
as
 begin

exec first procedure
exec second procedure
end

exec third procedure

你可以尝试一下。我确信它是多么合适。

IF both Stored procedure have same parameter then you can create a new store procedure
like

create third procedure
(@colname int)
as
 begin

exec first procedure
exec second procedure
end

exec third procedure

You can try it. I am sure how appropriate it is.

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