如何实现等待另一个作业完成的SQL Server作业?

发布于 2024-08-20 00:38:38 字数 432 浏览 7 评论 0原文

我正在寻找一种在 SQL Server 代理上实现优先步骤的方法,该步骤将验证特定作业是否正在运行。如果是这样,该步骤将进入“等待”状态,直到第一个作业成功完成。

为了澄清,这将是场景:

作业名称:“我的作业”

要检查的作业:“验证表”

“我的作业”的步骤:

第 1 步:检查“验证表”是否正在运行 第 2 步:做其他事情

在第 1 步中,需要使用一些 T-SQL,如下所示: exec msdb.dbo.sp_help_job @job_name='Validade table',@job_aspect ='JOB'

如果 current_execution_status 等于 1,则将等待(不会运行步骤 2)

我不是 SQL Server Agent 方面的专家,所以我需要一些帮助。

提前致谢。

I'm looking a way to implement a precedence step on SQL Server Agent that will verify is a specific job is running. If so, the step will entry in a "wait" state until first job finish with success.

To clarify, this will be the cenario:

Job Name: 'My Job'

Job to be checked: 'Validate tables'

Steps of 'My job':

Step 1: Check if 'Validate tables' is running
Step 2: Do something else

On Step 1, need to use some T-SQL like this:
exec msdb.dbo.sp_help_job @job_name='Validade tables',@job_aspect ='JOB'

If the current_execution_status is equal to 1, then will wait (will not run the step 2)

I'm not an expert on SQL Server Agent, so I need some help on this.

Thanks in advance.

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

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

发布评论

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

评论(2

若水微香 2024-08-27 00:38:38

为什么不使用第三个工作并将这两个工作作为第一个和第二个工作放在第三个工作中。这样它就不会重叠,并且只有在第一步完成后才运行。

Why don't you use a third job and stick these two jobs as Step one and Step two in the third job. That way it wolud not over lap and only run if First Step completed.

↙厌世 2024-08-27 00:38:38

看来您需要 SSIS 包。

It's look like you need SSIS package.

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