Executing Query Against Multiple SQL Server Instances

SQL Server

One of the less commonly known things you can do with SQL Server Management Studio (SSMS) is execute a script across multiple instances from inside SSMS. This makes mundane and tedious tasks somewhat easier by allowing you to execute the same Transact-SQL script one time and it effect multiple servers without changing your connection.

  1. Open SSMS (SQL Server 2008 and newer)
  2. Click the tab to select “Registered Servers” (or use Ctrl+Alt+G)
  3. Right-click on the tree-view and select “New Server Group…”
  4. Create a group, like your production group, development server group, etc.
  5. Add servers to the new group by selecting “New Server Registration”
  6. Once you have the new group and it contains some servers, right-click on the group and select “New Query”
  7. The new query window will open and create a connection to all the servers in the selected group
  8. You can verify this is true by looking at the bottom of the query window. The pink toolbar will show the number of servers you are currently connected to from this connection. Pink indicates you are connected to more than one server.



Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.