sqlserver 多表查詢不同數(shù)據(jù)庫服務(wù)器上的表
更新時間:2012年04月04日 18:44:06 作者:
sqlserver中多表查詢不同數(shù)據(jù)庫服務(wù)器上的表的實現(xiàn)方法,需要的朋友可以參考下
第一種方法:
/* 創(chuàng)建鏈接服務(wù)器 */
exec sp_addlinkedserver 'srv_lnk','','sqloledb','條碼數(shù)據(jù)庫IP地址'
exec sp_addlinkedsrvlogin 'srv_lnk','false',null,'用戶名','密碼'
go
/* 查詢示例 */
SELECT A.ListCode
FROM srv_lnk.條碼數(shù)據(jù)庫名.dbo.ME_ListCode A, IM_BarLend B
WHERE A.ListCode=B.ListCode
go
/* 刪除鏈接服務(wù)器 */
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
復(fù)制代碼 代碼如下:
/* 創(chuàng)建鏈接服務(wù)器 */
exec sp_addlinkedserver 'srv_lnk','','sqloledb','條碼數(shù)據(jù)庫IP地址'
exec sp_addlinkedsrvlogin 'srv_lnk','false',null,'用戶名','密碼'
go
/* 查詢示例 */
SELECT A.ListCode
FROM srv_lnk.條碼數(shù)據(jù)庫名.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
相關(guān)文章
vs code連接sql server數(shù)據(jù)庫步驟及遇到的問題小結(jié)
這篇文章主要介紹了用vs code連接sql server數(shù)據(jù)庫步驟及遇到的問題,本文通過圖文并茂的形式給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-05-05根據(jù)多條件查詢臨時表 想得到不同結(jié)果集的方法
很多情況下,需要采用多個參數(shù)來查詢一張臨時表,每個參數(shù)都要求得到不同的臨時表結(jié)果集。而往往某些參數(shù)并不對應(yīng)這張臨時表中的字段,而是對應(yīng)與該臨時表ID關(guān)聯(lián)的另一張表的字段。2009-11-11安裝MSDE2000提示為了安全起見,要求使用強 SA 密碼的解決方法
今天下載了一個msde2000A,本想按照平時的安裝習(xí)慣,找到了setup.exe安裝程序,錯誤提示彈出一個對話框:為了安全起見,要求使用強 SA 密碼。請使用SAPWD開關(guān)提供同一密碼。有關(guān)詳細信息,請參閱自述文件。安裝程序?qū)⒘⒓赐顺?/div> 2013-08-08SQL Server把某個字段的數(shù)據(jù)用一條語句轉(zhuǎn)換成字符串
這篇文章主要介紹了SQL Server把某個字段的數(shù)據(jù)用一條語句轉(zhuǎn)換成字符串,本文講解使用一條語句把字段中的數(shù)據(jù)查詢出來并以指定分割符組成字符串,需要的朋友可以參考下2015-07-07SQL Server中實現(xiàn)二進制與字符類型之間的數(shù)據(jù)轉(zhuǎn)換
在SQL Server 數(shù)據(jù)庫中,如何實現(xiàn)二進制數(shù)據(jù)與字符串?dāng)?shù)據(jù)之間的直接轉(zhuǎn)換2012-11-11sql server 自定義分割月功能詳解及實現(xiàn)代碼
這篇文章主要介紹了sql server 自定義分割月功能詳解及實現(xiàn)代碼的相關(guān)資料,需要的朋友可以參考下2016-10-10最新評論