sqlserver 多表查詢不同數(shù)據(jù)庫(kù)服務(wù)器上的表
發(fā)布日期:2022-01-19 10:05 | 文章來(lái)源:站長(zhǎng)之家
復(fù)制代碼 代碼如下:
/* 創(chuàng)建鏈接服務(wù)器 */
exec sp_addlinkedserver 'srv_lnk','','sqloledb','條碼數(shù)據(jù)庫(kù)IP地址'
exec sp_addlinkedsrvlogin 'srv_lnk','false',null,'用戶名','密碼'
go
/* 查詢示例 */
SELECT A.ListCode
FROM srv_lnk.條碼數(shù)據(jù)庫(kù)名.dbo.ME_ListCode A, IM_BarLend B
WHERE A.ListCode=B.ListCode
go
/* 刪除鏈接服務(wù)器 */
exec sp_dropserver 'srv_lnk','droplogins'
第二種方法:
復(fù)制代碼 代碼如下:
exec sp_configure 'show advanced options',1
reconfigure
exec sp_configure 'Ad Hoc Distributed Queries',1
reconfigure
go
select * from Product p inner join
opendatasource('SQLOLEDB','Data Source=Macaco-Online;user ID=sa;password=sa密碼;').Company.dbo.Product p2
on P.PID=p2.PID
go
exec sp_configure 'Ad Hoc Distributed Queries',0
reconfigure
exec sp_configure 'show advanced options',0
reconfigure
go
版權(quán)聲明:本站文章來(lái)源標(biāo)注為YINGSOO的內(nèi)容版權(quán)均為本站所有,歡迎引用、轉(zhuǎn)載,請(qǐng)保持原文完整并注明來(lái)源及原文鏈接。禁止復(fù)制或仿造本網(wǎng)站,禁止在非www.sddonglingsh.com所屬的服務(wù)器上建立鏡像,否則將依法追究法律責(zé)任。本站部分內(nèi)容來(lái)源于網(wǎng)友推薦、互聯(lián)網(wǎng)收集整理而來(lái),僅供學(xué)習(xí)參考,不代表本站立場(chǎng),如有內(nèi)容涉嫌侵權(quán),請(qǐng)聯(lián)系alex-e#qq.com處理。
相關(guān)文章