检查存储过程中的时间
我有一个需要很长时间才能执行的存储过程。我们希望它在夜间执行,但它必须时不时地检查当前时间,并且在给定时间它必须停止执行。我该怎么做?请向我提供可以在存储过程中使用的代码。我们使用的是 Microsoft SQL Server 2005。
I have a stored procedure that takes a lot of time to execute. We want it to execute during the night, but it has to check for the current time every now and then, and at a given time it has to stop executing. How do I do that? Please provide me with the code I can use in my stored procedure. We are using Microsoft SQL Server 2005.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以获取当前日期:
停止执行:
其中@date 是您想要停止执行的日期/时间
You can get the current date:
Stop executing:
Where @date is the date/time when you want to stop executing
创建维护计划并指定其开始时间。在此计划中创建“执行T-SQL语句任务”并为其指定执行超时(以秒为单位)。
Create Maintenance plan and sprecify start time for it. Create "Execute T-SQL statement task" in this plan and specify execution timeout for it (in seconds).
为什么你想要存在一个未完成的过程?就数据完整性而言,您不会让事情处于糟糕的状态或回滚您刚刚完成的所有工作吗?
尝试提高proc的性能不是更好的解决方案吗?
Why woudl you want to exist a proc that is not finished? Wouldn't you be leaving things in a bad state as far as data integrity or rolling back all the work you just did??
Wouldn't it be a better solution to try to improve the performance of the proc?