问题描述
有没有办法写一个T-SQL命令让它休眠一段时间?我正在异步编写一个 Web 服务,我希望能够运行一些测试来查看异步模式是否真的会使其更具可扩展性.为了模拟"运行缓慢的外部服务,我希望能够使用运行缓慢但实际上并未处理大量内容的脚本调用 SQL 服务器.
Is there to way write a T-SQL command to just make it sleep for a period of time? I am writing a web service asynchronously and I want to be able to run some tests to see if the asynchronous pattern is really going to make it more scalable. In order to "mock" an external service that is slow, I want to be able to call a SQL server with a script that runs slowly, but isn't actually processing a ton of stuff.
推荐答案
查看 WAITFOR 命令.
例如
-- wait for 1 minute
WAITFOR DELAY '00:01'
-- wait for 1 second
WAITFOR DELAY '00:00:01'
此命令允许您高度精确但仅在 10ms - 16ms 内在典型机器上准确,因为它依赖于 GetTickCount.因此,例如,调用 WAITFOR DELAY '00:00:00:001'
很可能根本不等待.
This command allows you a high degree of precision but is only accurate within 10ms - 16ms on a typical machine as it relies on GetTickCount. So, for example, the call WAITFOR DELAY '00:00:00:001'
is likely to result in no wait at all.
这篇关于T-SQL 中的睡眠命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!