October 14, 2009 at 9:58 am
Hey all, I'm wondering if there's a way to run one query against multiple registered servers in SSMS, SQL Server 2005. I realize this can be done in 2008.
Is there a registry key or entry somewhere in SSMS that I can loop thru to get the registered servers?
foreach 'registered server in ssms'
do
select @@SERVERNAME
end
My overall goal is to just see if they are all responding after our nightly reboots. I have SSMS installed on my local machine and want to run the query from there, instead of having to open Query windows for each instance.
TIA.
----------------------------------------------------------------------------
Sacramento SQL Server users group - http://sac.sqlpass.org
Follow me on Twitter - @SQLDCH
----------------------------------------------------------------------------
October 14, 2009 at 11:44 am
October 15, 2009 at 9:41 am
Definitely not elegant, but works. I used a DOS command line and the 'osql' utility:
FOR /F %s in (serverlist.txt) do osql -S %s -E -h-1 -Q "SELECT @@SERVERNAME"
Obviously, 'serverlist.txt' has a list of server names.
----------------------------------------------------------------------------
Sacramento SQL Server users group - http://sac.sqlpass.org
Follow me on Twitter - @SQLDCH
----------------------------------------------------------------------------
October 19, 2009 at 2:45 pm
Here is a method that utilizes the proc "xp_FixedDrives" as a convenient tool to query every server (and also send valuable info on drive space):
Declare @cmd varchar(500)
Declare @svr varchar(50)
Declare curServers Cursor
FOR
select [Name] from sys.servers
OPEN curServers
Fetch Next from curServers into @svr
WHILE @@Fetch_Status=0
BEGIN
Set @cmd='EXECUTE [' + @svr + '].Master..xp_FixedDrives'
-- Brackets are needed for instance names such as "Server1\SQLExpress"
Select @svr
Exec(@cmd)
Fetch Next from curServers into @svr
END
Close curServers
deallocate curServers
The cursor is necessary because the context must shift to each Master database in turn.
HTH
elliott
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply