I have a sql script as follow :
declare db_list cursor for
select name From sys.databases
open db_list
declare @var varchar(MAX)
fetch next from db_list into @var
print @var
while (@@FETCH_STATUS = 0)
BEGIN
EXEC('use '+@var)
print 'Checking database '+@var
print '---------------------------------------------'
dbcc checkdb
fetch next from db_list into @var
END
close db_list
deallocate db_list
I wish to get the result one by one. For instance, when @var is set to 'master'. It should show :
Checking database master
and then it should show 'dbcc checkdb' result for master.
Instead the result hangs for undefined time and then suddenly displays all results for all databases. I am using MS SQL Server 2008 for this.