Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have used WAITFOR combined with a cursor in the following script:

create table orders(orderId int primary key,productId int,productName varchar(20));

insert into orders values(1,11,'book');
insert into orders values(2,13,'flower');
insert into orders values(3,24,'microwave');
insert into orders values(4,7,'food');
insert into orders values(5,46,'clothes');

declare cur cursor for   
select * from orders;
open cur;
fetch next from cur;
    waitfor delay '00:00:01';
    fetch next from cur;
close cur;
deallocate cur;

I'm looking to display one record from the cursor per the specified interval of 1 second. For example: display the first row, then wait a second; display the second row, then wait a second; and so on. The cursor above does not do that. Say orders has 5 rows. The WHILE block waits 5 seconds and then displays all records together.

Is this the cursor's fault? How can I modify this script to work as intended?

share|improve this question

Add RAISERROR('', 0, 1) WITH NOWAIT before the delay to flush anything in the buffer to the client (SSMS?) first otherwise SQL Server will wait for more data to fill the packet.

Declare cur cursor for   
select * from orders   
open cur
fetch next from cur
    WAITFOR DELAY '00:00:01'
    fetch next from cur
close cur
deallocate cur
share|improve this answer

Unfortunately you cant use WAITFOR within a cursor, as I found out to my dismay. Best solution would be to rewrite the query without a CURSOR...?

share|improve this answer
Yes you can. screenshot of it all working fine – Martin Smith Mar 5 '15 at 21:57

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.