After the basic preparation is completed, the next step is to create, execute, modify, and delete the job
sp_add_job | Create a job |
sp_add_jobstep | Create one or more job steps |
sp_add_schedule | Create a plan |
sp_attach_schedule | Attach a plan to an activity |
sp_add_jobserver | Set the server for the job |
Of course, I personally find the friendly view much faster than executing these statements (achieved by right-clicking on the job - creating the job)
In the step, I personally prefer to write the statement to be executed as a stored procedure, and it is more convenient to only maintain the stored procedure later
When creating a new step, you may encounter this situation as shown in the figure below, because the component in the last parentheses is missing, you can refer to the link
https://www.cnblogs.com/lhp-net/archive/2013/01/22/2871462.html
In the plan, try to add a plan to send an email to the administrator if it fails, so as to avoid the situation that you don't know if the job execution fails, and some antivirus software will also block this job, if there is an antivirus engine, try to add a whitelist.
Tip, some stored procedures may be executed for more than a minute, this kind of execution on the page, the page will have a response timeout mechanism, and then report some errors, and the stored procedure cannot be executed.
If this happens, the stored procedure is really impossible to optimize, and the stored procedure can be placed in the job to execute the jobexecmsdb.dbo.sp_start_job@job_name='job_name'In this way, embarrassment can be avoided, and of course don't forget to remind the end of the execution.
exec msdb.dbo.sp_start_job @job_name='job_name'