Automatically refresh a query in SQL Server Management Studio?

fzwojiic  于 2023-08-02  发布在  SQL Server
关注(0)|答案(2)|浏览(110)

Is there a way to automatically refresh the result of a query in the SQL Server Management Studio (SQL Server 2008 R2)?

Currently I'm debugging an application which automatically inserts and updates data in a database and I'd like to track the progress without having to deposit a heavy object on the F5 key.

3pmvbmvn

3pmvbmvn1#

Try this:

SELECT GETDATE()              --your query to run
raiserror('',0,1) with nowait --to flush the buffer
waitfor delay '00:00:10'      --pause for 10 seconds
GO 5                          --loop 5 times

It will run the query 5 times, pausing for 10 seconds between each run

Output:

Beginning execution loop

-----------------------
2011-03-25 11:03:57.640
(1 row(s) affected)

-----------------------
2011-03-25 11:04:07.640
(1 row(s) affected)

-----------------------
2011-03-25 11:04:17.640
(1 row(s) affected)

-----------------------
2011-03-25 11:04:27.640
(1 row(s) affected)

-----------------------
2011-03-25 11:04:37.640
(1 row(s) affected)

Batch execution completed 5 times.
t3irkdon

t3irkdon2#

The only thing I can think of that would do that enitrely from SSMS would be a loop with a WAITFOR option. The problem is your output query window will simply have multiple result sets, each one later in your process than the one before it.

In this situation I usually suggest building a simple web page that runs from locally on your machine. Build it to take a query, and set it to auto-refresh every interval (30-60-90 seconds).

But that would be outside SSMS.

相关问题