How to get data from remote database using TSQL?
Is it possible to get data from remote server using JUST TSQL? I mean to do it just with script and without any actions (setting up linked servers and etc) on local server. Need t开发者_JS百科o query something Like this:
SELECT * FROM dbo.Users WHERE UserID NOT IN (SELECT UserID FROM [192.168.1.100].dbo.Users)
There are some ways to query remote servers via SQL (Remote Server, OPENQEURY), but i'm sure there is no way to query without setting up the connection in front.
But of cause you can set up your remote server connection using TSQL (see sp_addlinkedserver and sp_addlinkedsrvlogin)
You are required to link to the server aginst which you want to run the query. The ‘sp_addlinkedserver’is a system store procedure which can be used to link to the remote server server: following is the sample command.:
EXEC sp_addlinkedserver
@server = ‘SourceServer’
, @Srvproduct = ”
, @Provider = ‘SQLNCLI’
, @datasrc = ‘Remote SQL Server instance name’
I suggest you to please refer following link to know about how to run sql query on remote server http://ashishkhandelwal.arkutil.com/sql-server/sql-query-to-the-remote-sql-server/
精彩评论