WAITFOR Team

Given that the stored procedure on SQL Server 2005, which moves along the cursor, should be run once per hour, and it takes about 5 minutes to complete, but it takes a large piece of processor time:

edit: I would delete the cursor if I could, unfortunately, I need to do a bunch of processing and run other stored procs / queries based on the string.

Is it possible to use WAITFOR DELAY '0: 0: 0.1' before each selection to act as a SQL version of .Net Thread.Sleep? So that other processes run faster due to the execution time of this procedure.

Or is there another solution that I do not see?

thanks

+5
source share
5 answers

WAITFOR . WHILE - . , , , , .

declare @minid int, @maxid int, @somevalue int 
select @minid = 1, @maxid = 5
while @minid <= @maxid
begin
  set @somevalue = null
  select @somevalue = somefield from sometable where id = @minid
  print @somevalue
  set @minid = @minid + 1
  waitfor delay '00:00:00.1'
end
+4

, . IMHO , , , waitfor , .

, , , perfmon , , .

, , MS SQL Server, - .

+1

, . , . , ( SQL Server), .. , .

0

, , , , , .

, READONLY FASTWORD, , .

, , , WAITFOR . , .

The option should be to photograph the tables in the temp table, and then the cursor / loop instead. Then you will not lock the base tables, but equally the tables may change during the processing of the snapshot ...

Demes

0
source

All Articles