第一種方法:
復制代碼代碼如下:
/* 創建鏈接服務器 */
exec sp_addlinkedserver 'srv_lnk','','sqloledb','條碼數據庫IP地址'
exec sp_addlinkedsrvlogin 'srv_lnk','false',null,'用戶名','密碼'
go
/* 查詢示例 */
SELECT A.ListCode
FROM srv_lnk.條碼數據庫名.dbo.ME_ListCode A, IM_BarLend B
WHERE A.ListCode=B.ListCode
go
/* 刪除鏈接服務器 */
exec sp_dropserver 'srv_lnk','droplogins'
第二種方法:
復制代碼代碼如下:
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