|
1 | 1 | --- |
2 | | -description: "Execute Statements Against Multiple Servers Simultaneously" |
3 | | -title: Execute Statements Against Multiple Servers Simultaneously |
| 2 | +title: Execute statements against multiple servers simultaneously |
| 3 | +description: "Execute statements against multiple servers at the same time." |
| 4 | +author: markingmyname |
| 5 | +ms.author: maghan |
| 6 | +ms.reviewer: randolphwest |
| 7 | +ms.date: 12/21/2022 |
4 | 8 | ms.service: sql |
5 | 9 | ms.subservice: ssms |
6 | 10 | ms.topic: conceptual |
7 | | -helpviewer_keywords: |
| 11 | +ms.custom: seo-lt-2019 |
| 12 | +helpviewer_keywords: |
8 | 13 | - "multiserver queries" |
9 | 14 | - "executing queries against multiple servers" |
10 | 15 | - "queries [SQL Server], multiserver" |
11 | | -ms.assetid: 197760f3-0a06-43de-8162-69c27d3fbe56 |
12 | | -author: markingmyname |
13 | | -ms.author: maghan |
14 | | -ms.reviewer: "" |
15 | | -ms.custom: seo-lt-2019 |
16 | | -ms.date: 07/18/2016 |
17 | 16 | --- |
18 | | - |
19 | | -# Execute Statements Against Multiple Servers Simultaneously |
| 17 | +# Execute statements against multiple servers simultaneously |
20 | 18 |
|
21 | 19 | [!INCLUDE[SQL Server Azure SQL Database Synapse Analytics PDW](../../includes/applies-to-version/sql-asdb-asdbmi-asa-pdw.md)] |
22 | 20 |
|
23 | | -This topic describes how to query multiple servers at the same time in [!INCLUDE[ssnoversion](../../includes/ssnoversion-md.md)], by creating a local server group, or a Central Management Server and one or more server groups, and one or more registered servers within the groups, and then querying the complete group. |
24 | | - |
25 | | -The results returned by the query can be combined into a single results pane, or can be returned in separate results panes. The results set can include additional columns for the server name and the login used by the query on each server. Central Management Servers and subordinate servers can be registered by using only Windows Authentication. Servers in local server groups can be registered by using Windows Authentication or [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)] Authentication. |
26 | | - |
27 | | -> [!NOTE] |
28 | | -> Before you execute the following procedures, create a Central Management Server and server group. For more information, see [Create a Central Management Server and Server Group (SQL Server Management Studio)](./create-a-central-management-server-and-server-group.md). |
29 | | -
|
30 | | - |
31 | | -## <a name="Permissions"></a> Permissions |
32 | | - Because the connections maintained by a Central Management Server execute in the context of the user, by using Windows Authentication, the effective permissions on the registered servers might vary. For example, the user might be a member of the sysadmin fixed server role on the instance of [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)] A, but have limited permissions on the instance of [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)] B. |
33 | | - |
34 | | - ## Execute statements against multiple configuration targets simultaneously |
35 | | - |
36 | | -1. In SQL Server Management Studio, on the **View** menu, click **Registered Servers**. |
37 | | - |
38 | | -2. Expand a Central Management Server, right-click a server group, point to **Connect**, and then click **New Query**. |
39 | | - |
40 | | -3. In Query Editor, type and execute a [!INCLUDE[tsql](../../includes/tsql-md.md)] statement, such as the following: |
41 | | - |
42 | | - ``` |
43 | | - USE master |
44 | | - GO |
45 | | - SELECT * FROM sys.databases; |
46 | | - GO |
47 | | - ``` |
48 | | - |
49 | | - By default, the results pane will combine the query results from all the servers in the server group. |
50 | | - |
51 | | -#### To change the multiserver results options |
52 | | - |
53 | | -1. In [!INCLUDE[ssManStudio](../../includes/ssmanstudio-md.md)], on the **Tools** menu, click **Options**. |
54 | | - |
55 | | -2. Expand **Query Results**, expand **SQL Server**, and then click **Multiserver Results**. |
56 | | - |
57 | | -3. On the **Multiserver Results** page, specify the option settings that you want, and then click **OK**. |
58 | | - |
59 | | -## See Also |
60 | | - [Administer Multiple Servers Using Central Management Servers](../../relational-databases/administer-multiple-servers-using-central-management-servers.md) |
61 | | - |
| 21 | +This article describes how to query multiple servers at the same time in [!INCLUDE[ssnoversion](../../includes/ssnoversion-md.md)], by creating a local server group, or a Central Management Server and one or more server groups, and one or more registered servers within the groups, and then querying the complete group. |
| 22 | + |
| 23 | +The results returned by the query can be combined into a single results pane, or can be returned in separate results panes. The result set can include additional columns for the server name and the login used by the query on each server. Central Management Servers and subordinate servers can be registered by using only Windows Authentication. Servers in local server groups can be registered by using Windows Authentication or [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)] authentication. |
| 24 | + |
| 25 | +Before you execute the following procedures, create a Central Management Server and server group. For more information, see [Create a Central Management Server and Server Group (SQL Server Management Studio)](./create-a-central-management-server-and-server-group.md). |
| 26 | + |
| 27 | +## Permissions |
| 28 | + |
| 29 | +Because the connections maintained by a Central Management Server execute in the context of the user, by using Windows Authentication, the effective permissions on the registered servers might vary. For example, the user might be a member of the **sysadmin** fixed server role on the instance of [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)] A, but have limited permissions on the instance of [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)] B. |
| 30 | + |
| 31 | +## Execute statements against multiple configuration targets simultaneously |
| 32 | + |
| 33 | +1. In SQL Server Management Studio, on the **View** menu, select **Registered Servers**. |
| 34 | + |
| 35 | +1. Expand a Central Management Server, right-click a server group, point to **Connect**, and then select **New Query**. |
| 36 | + |
| 37 | +1. In Query Editor, type and execute a [!INCLUDE[tsql](../../includes/tsql-md.md)] statement, such as the following: |
| 38 | + |
| 39 | + ```sql |
| 40 | + USE master |
| 41 | + GO |
| 42 | + SELECT * FROM sys.databases; |
| 43 | + GO |
| 44 | + ``` |
| 45 | + |
| 46 | + By default, the results pane will combine the query results from all the servers in the server group. |
| 47 | + |
| 48 | +#### Change the multiserver results options |
| 49 | + |
| 50 | +1. In [!INCLUDE[ssManStudio](../../includes/ssmanstudio-md.md)], on the **Tools** menu, select **Options**. |
| 51 | + |
| 52 | +1. Expand **Query Results**, expand **SQL Server**, and then select **Multiserver Results**. |
| 53 | + |
| 54 | +1. On the **Multiserver Results** page, specify the option settings that you want, and then select **OK**. |
| 55 | + |
| 56 | +## See also |
| 57 | + |
| 58 | +- [Administer Multiple Servers Using Central Management Servers](../../relational-databases/administer-multiple-servers-using-central-management-servers.md) |
0 commit comments