SQL Server openquery,opendatasource 用法。

1, openquery 簡單用法。
exec sp_addlinkedserver
     @server='demo',--要連接的服務器別名
     @srvproduct='',
     @provider='SQLOLEDB',
     @datasrc='HNTV-DES'--要連接的服務器名稱

exec sp_addlinkedsrvlogin
     'demo',
     FALSE,
     NULL,
     'sa',
     '000000'            
Select * From openquery([demo],'Select * From test.aa.tb2')

 

2,OPENDATASOURCE  簡單用法

Select * From OPENDATASOURCE(
'SQLOLEDB','Data Source=192.168.0.11;Initial Catalog=Student;User Id=sa;Password=123456).Student.dbo.book

 

 

use master
go

exec sp_configure 'show advanced options',1
reconfigure
go
exec sp_configure 'Ad Hoc distributed Queries',1
reconfigure
go

Select * From OPENDATASOURCE(
'SQLOLEDB','Data Source=192.168.0.1;Initial Catalog=test;User Id=sa;Password=sa').test.dbo.tb1
go

exec sp_configure 'Ad Hoc Distributed Queries',0
reconfigure      
go

exec sp_configure 'show advanced options',0
reconfigure
go

 

發佈了42 篇原創文章 · 獲贊 4 · 訪問量 4萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章