There are two main approaches, depending on whether the servers are already linked and whether SQL Server Management Studio (SSMS) can be used.
- Use linked servers with four-part names (T-SQL only)
Assuming each remote instance is already defined as a linked server (for example: LSRV1, LSRV2, LSRV3) and each has the same table Q_TESTS in the same database and schema, run a query like:
SELECT 'LSRV1' AS ServerName, *
FROM LSRV1.YourDatabase.dbo.Q_TESTS
WHERE Act = 1
UNION ALL
SELECT 'LSRV2' AS ServerName, *
FROM LSRV2.YourDatabase.dbo.Q_TESTS
WHERE Act = 1
UNION ALL
SELECT 'LSRV3' AS ServerName, *
FROM LSRV3.YourDatabase.dbo.Q_TESTS
WHERE Act = 1;
Key points from the linked-server model:
- Each remote table is referenced with a four-part name:
<linked_server_name>.<catalog>.<schema>.<object_name>.
- All linked servers must already be created (for example with
sp_addlinkedserver) and working (test with sp_testlinkedserver).
- Use Central Management Server / Registered Servers (SSMS GUI)
If SSMS is available and the servers are registered in a Central Management Server (CMS) or a local server group:
- In SSMS, open View > Registered Servers (or press
Ctrl+Alt+G).
- Under Database Engine, expand Central Management Servers (or Local Server Groups) and locate the group that contains all target servers.
- Right-click the server group and select New Query.
- In the query window that opens, run:
SELECT *
FROM Q_TESTS
WHERE Act = 1;
- SSMS executes this statement on every server in the group simultaneously.
- By default, results from all servers are merged into a single grid, with an extra column showing the server name.
Multiserver result options (optional):
- In SSMS, go to Tools > Options > Query Results > SQL Server > Multiserver Results to:
- Ensure Add server name to the results is enabled.
- Choose whether to Merge results into one grid or show separate grids.
Either approach lets the same SELECT * FROM Q_TESTS WHERE Act = 1 run against all servers; linked servers do it from one central instance via T-SQL, while CMS/Registered Servers does it from SSMS.
References: