Very slow cursor

SQL_Hell

SQL Server DBA
Local time
Today, 18:39
Joined
Dec 4, 2003
Messages
1,361
Hi guys,

I am having problems with the following cursor which is being run accross multipe sql servers, I will run ok on the first server but when it get to the next server it just hangs indefinately

Code:
declare @server varchar(50),
	@servername varchar(50),
	@drive char(1),
	@sql varchar(200)

DECLARE server_cursor CURSOR STATIC FORWARD_ONLY
FOR SELECT distinct [srvname]
FROM 	   [ho-msx-srv].master.dbo.sysservers s inner join SQLAnalysis.dbo.tblServerDrives t ON  s.srvname = t.Servername
OPEN server_cursor
FETCH NEXT FROM server_cursor
INTO @server
WHILE @@FETCH_STATUS = 0
BEGIN

--select @server as server
set @sql = 'insert into SQLAnalysis.dbo.tblServerDrivesTMP exec ['+ @server + '].master.dbo.xp_fixeddrives'
--select @sql

exec(@sql)

select * from tblServerDrivesTMP



FETCH NEXT FROM server_cursor
INTO @server
END
	
CLOSE server_cursor
DEALLOCATE server_cursor

Any ideas?
 
Is the other server on the same network and/or switch? Distributed transactions take a huge performance hit if they are not.
 

Users who are viewing this thread

Back
Top Bottom