How do I schedule a job using sp_add_job to run every 10 seconds indefinitely? I am not sure if I am using the right parameters on the sp_add_jobschedule
.
Below is the T-SQL code I am using.
BEGIN TRY
BEGIN TRAN
DECLARE @jobId BINARY(16)
--Add job
EXEC msdb.dbo.sp_add_job @job_name=N'Update TimeStamp in table', @job_id = @jobId OUTPUT
--Add step to job
EXEC msdb.dbo.sp_add_jobstep @job_id=@jobId, @step_name=N'Do SQL Stuff',
@step_id=1,
@subsystem=N'TSQL',
@command=N'Exec StoredProc',
@database_name=N'DB',
@flags=0
--Add schedule to job
EXEC msdb.dbo.sp_add_jobschedule @job_id=@jobId, @name=N'every minute',
@freq_type=4, --
@freq_interval=64,
@freq_subday_type=0x2,
@freq_subday_interval=10,
@freq_relative_interval=0,
@active_start_date=20150403,
@active_end_date=99991231
COMMIT TRAN
END TRY
BEGIN CATCH
SELECT ERROR_Message(), ERROR_Line();
ROLLBACK TRAN
END CATCH