Sql queries not 'reporting' back until all queries have finish executing
I'm running a set of sql queries and they are not reporting the row affect until all the queries have ran. Is there anyway i can get incremental feedback.
Example:
DECLARE @HowManyLastTime int
SET @HowManyLastTime = 1
WHILE @HowManyLastTime <> 2400000
BEGIN
SET @HowManyLastTime = @HowManyLastTime +1
print(@HowManyLastTime)
END
This doesn't show the count till the loop has finished开发者_运维问答. How do i make it show the count as it runs?
To flush recordcounts and other data to the client, you'll want to use RaisError with NOWAIT. Related questions and links:
- PRINT statement in T-SQL
- http://weblogs.sqlteam.com/mladenp/archive/2007/10/01/SQL-Server-Notify-client-of-progress-in-a-long-running.aspx
In SSMS this will work as expected. With other clients, you might not get a response from the client until the query execution is complete.
SQL tends to be 'set-based', and you are thinking procedurally and trying to make it act systematically. It really doesn't make sense to do this in SQL.
I would be asking you motivation for doing this, and is there anything better that can be tried.
精彩评论