欧美激情网,国产欧美亚洲高清,欧美屁股xxxxx,欧美群妇大交群,欧美人与物ⅴideos另类,区二区三区在线 | 欧洲

知識學堂
  • ·聯(lián)系電話:+86.023-75585550
  • ·聯(lián)系傳真:+86.023-75585550
  • ·24小時手機:13896886023
  • ·QQ 咨 詢:361652718 513960520
當前位置 > 首頁 > 知識學堂 > 網(wǎng)站建設知識
SQL Server教程:讀取第三方數(shù)據(jù)庫的數(shù)據(jù)
更新時間:2012-01-09 | 發(fā)布人:本站 | 點擊率:587
現(xiàn)在需要在一臺服務器(A)上的數(shù)據(jù)庫(Master)里訪問另外一臺服務器(B)的另外兩個數(shù)據(jù)庫(NZ 和 AU)。AU 和 NZ 是網(wǎng)站的部分實時數(shù)據(jù),目前某一步操作的REPLICATION方案是從服務器B到A,AU / NZ 的表結構同Master 數(shù)據(jù)結構基本一致。
 
這樣一來,當把AU Replication 到 Master 后,在把 NZ  Replication 到 Master , Master 里的就只剩 NZ 的數(shù)據(jù)了。反過來就只有AU的了,具體的Replication 是怎么一回事,我也不懂,也沒有細看。
 
如果能在Master 里直接操作 AU 和 NZ 就好了。
SQLServer 有函數(shù):
OPENROWSET 和 OPENDATASOURCE
 
這兩個函數(shù)不但能實現(xiàn)從另外的數(shù)據(jù)庫讀數(shù)據(jù),而且還能從EXCEL、TXT, ORACLE, ODBC 等讀數(shù)據(jù)。
--啟用Ad Hoc Distributed Queries:
exec sp_configure 'show advanced options',1
reconfigure
exec sp_configure 'Ad Hoc Distributed Queries',1
reconfigure
 
SELECT *
FROM OPENDATASOURCE(
'SQLServerName;User ID=sa;Password=xxx'
).Help.dbo.Help_Category
 

 
select * from openrowset( ' 
 
--關閉Ad Hoc Distributed Queries:
exec sp_configure 'Ad Hoc Distributed Queries',0
reconfigure
exec sp_configure 'show advanced options',0
reconfigure
 
 
但是,這樣寫著有點復雜,而且不便于維護,假如數(shù)據(jù)庫密碼改變了,就需要把一個一個把密碼改正。
 
 
Oracle 里有 DB Link, 而且語法非常簡潔。
 
 
查了一下幫助,
SQLServer 里有 "鏈接服務器"  這個東東。要創(chuàng)建 鏈接服務器需要用到SQLServer 的一個系統(tǒng)存儲過程:
 
sp_addlinkedserver [ @server= ] 'server' [ , [ @srvproduct= ] 'product_name' ]
     [ , [ @provider= ] 'provider_name' ]
     [ , [ @datasrc= ] 'data_source' ]
     [ , [ @location= ] 'location' ]
     [ , [ @provstr= ] 'provider_string' ]
     [ , [ @catalog= ] 'catalog' ]
 
 
exec sp_addlinkedserver @server= 'XLING' , @srvproduct = '', @provider = ' QQ空間 新浪微博 開心網(wǎng) 人人網(wǎng)