SQL 如何每小时在sql server中运行一个存储过程?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2348863/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to run a stored procedure in sql server every hour?
提问by Shantanu Gupta
I have a table on which I want to perform some operations every hour. For this I created a Stored Procedure but don't know how to call it every hour. I know there are some kind of scheduled jobs, but how to use them.
我有一张桌子,我想每小时在上面执行一些操作。为此,我创建了一个存储过程,但不知道如何每小时调用它。我知道有一些预定的工作,但如何使用它们。
Is there some kind of service also that keeps on running continuously, every second, where I can place my piece of code to be executed ?
是否还有某种服务每秒持续运行,我可以将我的代码放在何处执行?
回答by SQLMenace
In SSMS navigate to SQL Server Agent-->Jobs Right click on the Job Folder and select new job
在 SSMS 中导航到 SQL Server 代理--> 作业右键单击作业文件夹并选择新作业
on the dialog that pops up, give the job a name click on steps, then on new, you will see a dialog like the following, pick correct DB and type your proc name
在弹出的对话框中,为作业命名单击步骤,然后在新建上,您将看到如下所示的对话框,选择正确的数据库并输入您的进程名称
after that click on schedule, pick new and you will see something like the image below, fill all the stuff you need and click ok, click ok on the job and you should be set
在点击计划之后,选择新的,你会看到如下图所示的东西,填写你需要的所有东西并点击确定,在工作上点击确定,你应该被设置
回答by garik
1) Use the SQL Server Agent (open MS Management Studio) 2) New Job 3) Add Step 4) Choose Transact SQL 5) EXEC MyStroredProc 6) Choose database 7) Add schedule 8) Occurs every hour
1) 使用 SQL Server 代理 (打开 MS Management Studio) 2) 新作业 3) 添加步骤 4) 选择 Transact SQL 5) EXEC MyStroredProc 6) 选择数据库 7) 添加计划 8) 每小时发生一次
Add notification to know that process is doing well (or bad).
添加通知以了解进程运行良好(或不良)。
In the properties of SQL Server Agent check that all Auto restart options are switch ON
在 SQL Server 代理的属性中,检查所有自动重启选项是否都打开
回答by Russ Cam
Set up a SQL Server agent job to execute the stored procedure at 1 hour intervals
设置 SQL Server 代理作业以 1 小时为间隔执行存储过程