Databases Reference
In-Depth Information
Monitoring for job creation and scheduling follows techniques you
learned in previous chapters. For example, to schedule a job in SQL Server
that would take the event information into a file, you can use:
-- Add the job
EXECUTE @ReturnCode = msdb.dbo.sp_add_job
@job_id = @JobID OUTPUT ,
@job_name = N'trojan',
@owner_login_name = N'sa',
@description = N'Get Login/Logout events',
@category_name = N'[Uncategorized (Local)]',
@enabled = 1, @notify_level_email = 0,
@notify_level_page = 0,
@notify_level_netsend = 0,
@notify_level_eventlog = 2,
@delete_level= 0
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
-- Add the job steps
EXECUTE @ReturnCode = msdb.dbo.sp_add_jobstep
@job_id = @JobID, @step_id = 1,
@step_name = N'RunSproc',
@command = N'Exec sp_trojan',
@database_name = N'pubs',
@server = N'', @database_user_name = N'',
@subsystem = N'TSQL',
@cmdexec_success_code = 0,
@flags = 0,
@retry_attempts = 0,
@retry_interval = 0,
@output_file_name = N'',
@on_success_step_id = 0,
@on_success_action = 1,
@on_fail_step_id = 0, @on_fail_action = 2
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
EXECUTE @ReturnCode = msdb.dbo.sp_update_job
@job_id = @JobID,
@start_step_id = 1
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
-- Add the job schedules
EXECUTE @ReturnCode = msdb.dbo.sp_add_jobschedule
@job_id = @JobID,
@name = N'ScheduledUpdates',
@enabled = 1,
 
Search WWH ::




Custom Search