T-sql script for Job

USE msdb ;
GO

EXEC dbo.sp_add_job
@job_name = N'ForecastDataJob' ;
GO

EXEC sp_add_jobstep
@job_name = N'ForecastDataJob',
@step_id = 1,
@step_name = N'Generate Weekly Consumption Data',
@subsystem = N'TSQL',
@command = N'EXECUTE Forecast.GenerateWeeklyConsumptionData 106',
@on_success_action = 3,
@on_success_step_id = 2,
@database_name = N'demo-psi-drc.mangoserver.net',
@retry_attempts = 5,
@retry_interval = 10 ;
GO

EXEC sp_add_jobstep
@job_name = N'ForecastDataJob',
@step_id = 2,
@step_name = N'Generate Weekly Forecast Data',
@subsystem = N'TSQL',
@command = N'EXECUTE Forecast.GenerateWeeklyForecastData 106',
@database_name = N'demo-psi-drc.mangoserver.net',
@retry_attempts = 5,
@retry_interval = 10 ;
GO

declare @sid int;
EXEC dbo.sp_add_schedule
@schedule_name = N'ExecuteForecastDataJob',
@freq_type = 4,
@freq_interval = 1,
@active_start_date=20130301,
@active_start_time = 235959,
@schedule_id = @sid out;

select @sid;

EXEC sp_attach_schedule
@job_name = N'ForecastDataJob',
@schedule_id = @sid ;
GO

 

http://msdn.microsoft.com/en-us/library/ms187320(v=sql.105).aspx

posted @ 2013-03-27 15:00  落叶潇潇雨  阅读(344)  评论(0编辑  收藏  举报