The first method:
Copy Code code as follows:
/* Create a linked server <span class="Apple-converted-space"></span> /*
exec sp_addlinkedserver ' srv_lnk ', ', ' SQLOLEDB ', ' Barcode database IP address '
exec sp_addlinkedsrvlogin ' Srv_lnk ', ' false ', NULL, ' username ', ' password '
go
/* Query Sample * <span class="Apple-converted-space"></span> *
SELECT a.listcode
from Srv_lnk. Barcode database name. Dbo.me_listcode A, im_barlend B
WHERE a.listcode=b.listcode
Go
/* Delete the linked server <span class="Apple-converted-space"></span> /*
exec sp_dropserver ' srv_lnk ', ' droplogins '
the second method:
Copy Code code as follows:
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 password; '). 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