0

我正在尝试从链接服务器中读取数据,并且连接只带回第一个匹配项。如果我直接在远程服务器上运行查询,我会得到多行。本地和远程服务器都是 Azure 托管实例。@@Version 显示:

Microsoft SQL Azure (RTM) - 12.0.2000.8   May 15 2020 00:47:08   Copyright (C) 2019 Microsoft Corporation 

查询如下:

DECLARE @Id INT = 15;

SELECT 'LinkedServerMI lnkSvr w/join' fromSrc, *
FROM LinkedServer.DatabaseName.dbo.CustomerInfoPhone cip
   INNER JOIN dbo.CustomerInfo ci ON cip.CustomerInfoId = ci.CustomerInfoId -- Simple join
WHERE ci.CustomerInfoId = @Id; -- No other filters
-- One row comes back, expected 2 or more

SELECT 'LinkedServerMI lnkSvr select only' fromSrc, *
FROM LinkedServer.DatabaseName.dbo.CustomerInfoPhone cip
WHERE cip.CustomerInfoId = @Id;
--For the customer id in question 2 rows come back.

链接服务器的创建方式如下:

EXEC master.dbo.sp_addlinkedserver @server = N'LinkedServer', @srvproduct=N'SQL', @provider=N'MSOLEDBSQL', @datasrc=N'<servername>', @provstr=N'Data Source=<servername>;User ID=<remoteuser>;ApplicationIntent=ReadOnly'
EXEC master.dbo.sp_addlinkedsrvlogin @rmtsrvname=N'LinkedServer',@useself=N'False',@locallogin=NULL,@rmtuser='<remoteuser>',@rmtpassword='########';

查询计划大到共享。此链接应允许您查看托管在 Google 上的文件:Linked Server Query Plan

4

0 回答 0