Tuesday, February 24, 2015

How to Execute Query Against Multiple Servers?

Before executing Multiple Server query, first we need to create a Registered SQL Server Group with all required servers for which we want to execute the Query.

To Create Registered Servers Group follow the below steps in SSMS:

1: In SQL Server Management Studio, on the View menu, click Registered Servers.(Or simply pess ctrl+alt+G)
2: Now Right click on Local Server Groups > New Server Registration



Enter login credentials for same.  



Test the connection and save itAdd all your desired server. Then open a new query editor and execute the query as below:

Use master
Go
Select * from Sys.Databases
Go

The results set includes additional columns for the server name and the login that is used by the query on each server. By default server name is included in result set but for login name we have to enable it from Query options.


So, this is how we can execute Query Against Multiple Servers.

Thanks!!!

No comments:

Post a Comment