[英]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 . table位于名为database1的数据库中名为tbl1的 server1上 。
the query that i am running is querying data located on server2. 我正在运行的查询是查询位于server2上的数据。
for the insert command, would this work: server1.database1.tbl1 对于insert命令,这是否有效: server1.database1.tbl1
If you need more information please let me know. 如果您需要更多信息,请告诉我。
Fully qualified remote names have 4 parts: servername.databasename.schemaname.tablename
. 完全限定的远程名称有4个部分:
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. 您可以使用它们执行任何操作,包括INSERT-SELECT,只要正确配置链接服务器以进行更新,并且正确配置MSDTC以使两个服务器参与分布式事务。
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)
您在server2上的insert命令可以工作,但前提是server1在server2中注册为链接服务器 。
Assuming you've created a linked server for server1, with appropriate permissions, you should be able to: 假设您已经为server1创建了具有适当权限的链接服务器 ,您应该能够:
insert into server1.database1.dbo.tbl1
select ...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.