SQL Server 代理作业:如何在不执行整个作业的情况下执行作业步骤
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6412950/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
SQL Server Agent Jobs: How to execute a job step without executing the entire job
提问by RLH
I have a SQL Server Agent Job that previously had two steps. Today, I've had to integrate a third step and soon I'll need to integrate a fourth.
我有一个以前有两个步骤的 SQL Server 代理作业。今天,我必须集成第三步,很快我将需要集成第四步。
I want to be sure that the step will execute properly but I do not want to execute the entire job.
我想确保该步骤将正确执行,但我不想执行整个作业。
The first two steps take quite a bit of time to execute and during the day they hog a significant amount of the SQL resources that my user's need.
前两个步骤需要相当多的时间来执行,并且在白天它们占用了我的用户需要的大量 SQL 资源。
Is there a way that I can execute a job step and not an entire job process?
有没有办法可以执行工作步骤而不是整个工作流程?
Within SSMS, if I right-click on the job there is an option that states "Start Job at step..." except when I try that options it brings up a dialog that seems to imply that the entire job has been started. What can I do to test one step within a job?
在 SSMS 中,如果我右键单击作业,则会有一个选项显示“在步骤开始作业...”,除非我尝试该选项时会弹出一个对话框,似乎暗示整个作业已开始。我可以做什么来测试工作中的一个步骤?
Thanks in advance.
提前致谢。
回答by Rich
"Start job at step" will start the job at the step you specify. However - if you don't wish to execute any subsequent steps - be sure to adjust the step logic so that it will "Quit reporting success" after completing the step you started at.
“在步骤开始作业”将在您指定的步骤开始作业。但是 - 如果您不想执行任何后续步骤 - 请务必调整步骤逻辑,以便在完成您开始的步骤后“退出报告成功”。
回答by Mehrdad Alemi
Use this:
用这个:
EXEC msdb.dbo.sp_start_job N'job_name' , 'step_name'
回答by James Jenkins
In SSMS:
在 SSMS 中:
- Copy the code from the job step (use ctrl + a to select all)
- Paste the code in to a new query window in SSMS
- Run the code
- 复制作业步骤中的代码(使用 ctrl + a 全选)
- 将代码粘贴到 SSMS 中的新查询窗口
- 运行代码
Alternately if you have a recurring need to run just a couple steps.
或者,如果您经常需要运行几个步骤。
Put those steps in a separate job, then kick off one job from the other to run everything. Use EXEC msdb.dbo.sp_start_job N'job_name'
将这些步骤放在一个单独的工作中,然后从另一个工作开始,运行所有内容。用EXEC msdb.dbo.sp_start_job N'job_name'
You can run the short easy job on demand, and the full long job as scheduled
您可以按需运行简短的简单作业,并按计划运行完整的长期作业
回答by madhukar mohan
Go to job properties and manually do that step. For example, there is a job with 16 steps and you want to run the 12th step, then go to that job property and see what that step 12 exactly does. If it executes a batch file in command prompt, do that manually. But this logic cannot be used in all cases.
转到作业属性并手动执行该步骤。例如,有一个有 16 个步骤的作业,您想运行第 12 个步骤,然后转到该作业属性并查看第 12 步的确切作用。如果它在命令提示符下执行批处理文件,请手动执行。但这种逻辑并非在所有情况下都可以使用。