Reputation: 7143
I'm working on an administration application where system admins can schedule an outage. In order to make the outage happen I need to run a simple update statment on a single table. The problem is that I want them to be able to log in at lets say 12PM and schedule an outage at 9PM, so that we don't have to have staff online to do this.
Is there some kind of built-in way in SQL Server to schedule an update stmt like this?
Ideally my admin web app would be able to invoke something on SQL Server and say run this at 9PM and not before, otherwise I know I can create a thread and timer to run the update in my webapp but that idea just makes me cringe...
Thanks in advance. Chris
Upvotes: 0
Views: 51
Reputation:
SQL Server Agent is one way, as Sir Crispalot explained. But if you want something really low-rent that will work even if you are on SQL Azure or SQL Server Express (which don't support SQL Server Agent), SQL Server Agent is disabled, or you don't have the rights to create jobs, T-SQL can also do this:
WAITFOR TIME '21:00:00';
---- do your thing here;
Then of course there are other external options - a worker role in Azure, task scheduler in Windows, the job mechanism in PowerShell... all of which can either directly or indirectly invoke some SQL or call a stored procedure.
Upvotes: 1
Reputation: 4844
I think you might be looking for the SQL Server Agent.
You can use it to do pretty much anything you like - run a backup plan, call a stored procedure, etc.
This documentation should give you the pointers you need to get started, and specifically this explains how to create a job.
Upvotes: 0