用SQL 语句实现调度:
1.建立作业:
declare @id BINARY(16)
exec msdb..sp_add_job @job_name = N'zb backup1', @enabled = 1, @start_step_id = 1, @notify_level_eventlog = 2, @notify_level_email = 0, @notify_level_netsend = 0, @notify_level_page = 0, @delete_level = 0, @category_name = N'[Uncategorized (Local)]', @job_id = @id OUTPUT
select @id
2.建立作业步骤:(@job_id =后的0xC26AFAA61F7F0D4BB30017A9D57F39D7是在建立作业时的@id,以数据库zb为例,每天两点钟覆盖备份到C:/zbsql4.9)
msdb..sp_add_jobstep @job_id = 0xC26AFAA61F7F0D4BB30017A9D57F39D7, @step_id = 1, @cmdexec_success_code = 0, @on_success_action = 1, @on_success_step_id = 0, @on_fail_action = 2, @on_fail_step_id = 0, @retry_attempts = 0, @retry_interval = 0, @os_run_priority = 0, @flags = 0, @step_name = N'Step 1', @subsystem = N'TSQL', @command = N'BACKUP DATABASE [zb] TO DISK = N''C:/zbsql4.9'' WITH INIT , NOUNLOAD , NAME = N''zb backup'', SKIP , STATS = 10, NOFORMAT ', @database_name = N'master'
3.确定调度时间:(@job_id =后的0xC26AFAA61F7F0D4BB30017A9D57F39D7是在建立作业时的@id,以数据库zb为例,每天两点钟覆盖备份到C:/zbsql4.9)
exec msdb..sp_add_jobschedule @job_id =0xC26AFAA61F7F0D4BB30017A9D57F39D7, @name = N'Schedule 1', @enabled = 1, @freq_type = 4, @freq_interval = 1, @freq_subday_type = 1, @freq_subday_interval = 0, @freq_relative_interval = 0, @freq_recurrence_factor = 1, @active_start_date = 20020519, @active_end_date = 99991231, @active_start_time = 20000, @active_end_time = 235959
SQL 2000的联机帮助是中文的,如不明白参数可以查阅帮助文件,代理Agent服务要启动,不然不会自动备份。