Use mastergo--definition Create job declare @jobid uniqueidentifier, @jobname sysnameset @jobname = N ' Testinterval ' IF EXISTS (SELECT * FRO M msdb.dbo.sysjobs WHERE [email protected]) EXEC msdb.dbo.sp_delete_job @[email protected]exec msdb.dbo.sp_ Add_job@job_name = @jobname, @job_id = @jobid output--Define job step declare @sql nvarchar (4000), @dbname sysnameselect @dbname =db _name (),---the job step executes @sql=n '--job step content ' in the current database--typically defines a job that is handled with TSQL, which defines the Transact-SQL statement to execute EXEC msdb.dbo.sp_add_ jobstep@job_id = @jobid, @step_name = N ' Step one ', @subsystem = ' TSQL ',--type of step, generally tsql@[email protected], @command = @ sql--Create a schedule (using several of the job scheduling templates specifically defined later) EXEC msdb. sp_add_jobschedule@job_id = @jobid, @name = N ' First dispatch ', @freq_type = 8,--frequency of execution @freq_interval=4,--in Tuesday execution @freq_subday_type=0x8,--repeat mode, 0x1= at a specified time, 0x4= how many minutes, 0x8= how many hours to execute once. 0x1 is used with @active_start_time, @active_start_time specifies the time to start execution, which is performed only once in the frequency interval specified by @freq_type-if 0x4 or 0x8, As long as you specify @freq_subday_interval, the @freq_subday_interval represents every number of minutes (when @freq_suBDAY_TYPE=0X4) or the number of hours (when @freq_subday_type=0x8) performed @freq_subday_interval=2, the number of repetitions, where @active_start_date = NULL is performed once per hour ,--The start date of the job execution, which is null when the current date is yyyymmdd@active_end_date = 99991231,--the stop date of the job execution, the default is 99991231, and the format is Yyyymmdd@active_ Start_time = 020000,--start time of job execution, format hhmmss@active_end_time = 030000,--stop time for job execution, formatted as Hhmmss@freq_recurrence_factor = 2 --execution interval two weeks--reference--http://www.cnblogs.com/lijun198504/articles/1352558.html--http://msdn.microsoft.com/zh-cn/ library/ms366342.aspx--Add target server exec msdb.dbo.sp_add_jobserver @job_id = @jobid, @server_name = N ' (local) '
SQL Server uses scripts to create jobs