Am new to SQL Server, and trying to learn how to do SQL Server Jobs. I executed this simple example from msdn in a SQL Server Express instance I have installed.
USE msdb ;
GO
EXEC dbo.sp_add_job
@job_name = N'Weekly Backup' ;
GO
EXEC sp_add_jobstep
@job_name = N'Weekly Backup',
@step_name = N'Set database to read only',
@subsystem = N'TSQL',
@command = N'ALTER DATABASE SALES SET READ_ONLY',
@retry_attempts = 5,
@retry_interval = 5 ;
GO
EXEC dbo.sp_add_schedule
@schedule_name = N'ROce',
@freq_type = 1,
@active_start_time = 212600 ;
USE msdb ;
GO
EXEC sp_attach_schedule
@job_name = N'Weekly Backup',
@schedule_name = N'ROce';
GO
EXEC dbo.sp_add_jobserver
@job_name = N'Weekly Backup';
GO
-- Start the job
USE msdb;
GO
EXEC dbo.sp_start_job N'Weekly Backup';
GO
I have set the @active_start_time = 212600 When I executed this script, the system time was 21hrs23minutes. So, the job should have executed in 3 minutes from then. I waited till 21.30hrs and then checked the jobs executed history, but don't see it : I used this script to see jobs'-executed history:
SELECT sj.name,
sja.run_requested_date,
CONVERT(VARCHAR(12), sja.stop_execution_date- sja.start_execution_date, 114) Duration
FROM msdb.dbo.sysjobactivity sja
INNER JOIN msdb.dbo.sysjobs sj
ON sja.job_id = sj.job_id
WHERE sja.run_requested_date IS NOT NULL
ORDER BY sja.run_requested_date desc
I also tried another script I got from the web:
select
j.name as 'JobName',
msdb.dbo.agent_datetime(run_date, run_time) as 'RunDateTime',
((run_duration/10000*3600 + (run_duration/100)%100*60 + run_duration%100 + 31 ) / 60)
as 'RunDurationMinutes'
From msdb.dbo.sysjobs j
INNER JOIN msdb.dbo.sysjobhistory h
ON j.job_id = h.job_id
where j.enabled = 1 --Only Enabled Jobs
--and j.name = 'TestJob' --Uncomment to search for a single job
order by JobName, RunDateTime desc
But none of the jobs are listed. Is it that the job is not even executing? I tried renaming the job and restarting it, but no...doesn't work. I don't have SQL Server Agent, as it doesn't come with the Express edition. Please help.