Inserting the output of a query into a table created on a different server SQL Server 2008
I was wondering if someone can guide me as to how I can insert the output of a query into a table that I created on a different server from where I am running my query.
For example:
table is located on server1 called tbl1 in a database called database1.
the query that i am running is querying data located on server2.
for the insert command, would this work: server1.database1.tbl1
If you need more information pleas开发者_JS百科e let me know.
As long as you can reach both servers, it should be easy enough:
INSERT INTO server1.database1.dbo.tbl1(list of columns)
SELECT
(list of columns)
FROM
server2.database2.dbo.tbl2
WHERE
(some condition here)
Fully qualified remote names have 4 parts: servername.databasename.schemaname.tablename
. You can do any operation with them, including INSERT-SELECT, as long as the linked server is properly configured for updates and the MSDTC is properly configured for the two servers to engage in a distributed transaction.
Your insert command on server2 would work but only if server1 is registered as linked server in server2.
Assuming you've created a linked server for server1, with appropriate permissions, you should be able to:
insert into server1.database1.dbo.tbl1
select ...
精彩评论