Sql-Server

如何在 Sql server 2008 中安排作業少於 10 秒?

  • December 11, 2015

我想每 3 秒執行一次作業,但是在 SQL Server 2008 中,我們不能定義小於 10 秒的間隔。

該作業用於將訪問者資訊和分段資訊插入/更新到由Google搜尋跟踪的數據庫中。

在 2 或 3 秒內最多插入大約 100 行。該作業在數據庫中插入和更新表。有沒有辦法使用 sp 作業調度配置來安排它?

創建一個計劃每分鐘開始的作業。讓工作執行以下操作:

WHILE 1=1
BEGIN
   EXEC dbo.SomeProcedure; /*  this would be the 
       name of a stored procedure that does the 
       actual work */
   WAITFOR DELAY '00:00:03.000';
END

我不認為這個答案是正確的。原因如下:假設 dbo.SomeProcedure 將執行 2 秒並在上午 10:00:00 開始,然後在此 proc 完成後,它將再等待 3 秒再重新啟動,即上午 10:00:02 , 結束,直到上午 10:00:05 才開始。如果我們真的可以安排一個作業每 3 秒執行一次,那麼 dbo.SomeProcedure 確實會在上午 10:00:00 和上午 10:00:03 執行,以此類推。更準確的應該是以下內容:

   WHILE 1=1
   BEGIN
     EXEC dbo.SomeProcedure; /*  this would be the 
     name of a stored procedure that does the actual work */

     WHILE datediff(second, @dt, getdate())%3 <> 0
       WAITFOR DELAY '00:00:00.100'; -- can be made it to '00:00:00.001'
  END

引用自:https://dba.stackexchange.com/questions/76802