Is there a way to pause a scheduled job in SQL Server to NOT run between two times a day?
I have a recurring job that starts every 2 hours, daily from 12am. However, I want the job to not run between 4pm and 6pm. So I want it to run as follows:
12am, 2am, 4am, 6am, 8am, 10am, 12pm, 2pm, 8pm, 10pm and back to midnight.
Is that possible?
Thanks
I'm afraid you have to split your job in two schedules
(12am to 4pm and 6pm to 10pm).
You can handle this by implementing your own scheduling with a data model and some stored procedures.
Hope it helps.
Kind Regards,
Related
How can I schedule to run once on the first business day of every month in SQL Server JOB application?
Under Frequency, you can choose "The first weekday of every 1 month(s)".
It won't handle holidays, but as far as I know that's the closest you can get with the schedule configuration.
On the SQL Server log shipping secondary database server, I have 2 jobs LS_Copy and LS_Restore.
Current schedule: both jobs run every 30 minutes (all day)
New schedule: I want to change the restore job to run every 30 minutes between 10:00 AM to 7:00 PM and 6:30 AM to 7:30 AM. It won't be running for the remainder of the day.
The copy job will still have the same schedule, i.e., every 30 minutes (all day)
Question: do you know if making this change can create issues I am unaware of?
I modified the schedule to new one, everything is working fine. The copy job piles up the files and whenever restore executes, it processes all the queued files in correct order.
Not a technical question as such, but I do wonder how other people deal with the Schedules in SQL Server in relation to SQL Agent.
Personally, I like to create a bunch of schedules and then reuse them for various jobs.
As an example, I like to name my schedules in the following manner:
Daily - Every 15 seconds midnight to midnight
Daily - Every 15 seconds between 03:20 and 23:55
Daily - Every 22 minutes from midnight to midnight
Daily - Every 3 hours - starting at 03:30 to 23:59:59
Daily - Every 30 seconds from 00:00:05
It's not that stringent, but it helps me to understand the schedules a little better.
And then, I like to associate my jobs with existing schedules (the rule in the team is : DO NOT modify schedules)
So I do end up with a number of schedules that are linked to numerous jobs.
Discussing this with a colleague and wondering what is the correct approach, most efficient approach to this, we tested things a little.
One behaviour I thought was surprising is as follows:
create a new job
during that process, create a new schedule and associate it to that job
run the job once (mine was "SELECT 1 as one") to be sure to be sure
then drop that SQLAgent job
I would have expected the schedule to remain, but as it turns out the newly created schedule is also dropped!
How do others feel about that? is this correct behaviour?
And do you prefer to create a new schedule for every new job you create? or re-use Schedules?
Hoping to hear interesting views,
Kindest,
B
I'm not sure this is entirely opinion based, but I also won't be surprised if it gets flagged as such.
In the shop where I had the most sway over job scheduling, we opted to create new schedules for each job. Sometimes just one, sometimes several. That way, if we were experiencing high load on any given server, we could tweak individual job schedules to spread out the load without impacting multiple jobs. Say, for instance, one of 6 jobs with the same start time started to process exponentially more data, that one job could easily be shifted by X minutes so it wasn't competing for resources, or causing competition.
I stuck in a issue from last 6 months. I had a SQL Servre job SALES lOAD which is created with a T-SQL script. This job is being recreated every month automatically. How we know which job affected or recreated my SALES lOAD load every month. I checked each and every job but no job is affecting this job
You may check if there is any process scheduled to run every month (BAT file,Task scheduler job, etc...)
I need to be able to schedule a job on the 10th of each month and have it run for a set number of days or until a specified date.
Is there any way to customize sql server agent jobs using some sort of API or something?
Thanks.
You can accomplish using the SQL Job Schedule properties by using more than one schedule for the job. You can schedule the job to run on the 10th day of the month (with the option for an end date). You can then create multiple schedules, one for the 11th, 12th, etc.
The SQL Server Agent does not have a schedule option like you need, so I think your workaround is as good as it gets for keeping it inside SQL Server.
The Windows Task Scheduler however does have an option to run a job on the 'x' day of the month, maybe kicking your sproc off using sqlcmd via Windows Task Scheduler is an alternate solution?
Hope this helps
I still can't find any way of customizing the job schedule, but I have figured a way around it by adding the condition to the job step:
IF (DAY(GetDate()) >= 10)
EXEC MySP
And setting the schedule to run every day.