将表复制到不同 SQL Server 上的不同数据库 [英] Copy table to a different database on a different SQL Server

查看:25
本文介绍了将表复制到不同 SQL Server 上的不同数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将一个表从一个数据库复制到另一个数据库.我知道如果数据库位于同一 SQL Server 上,您可以轻松执行以下操作.

I would like to copy a table from one database to another. I know you can easily do the following if the databases are on the same SQL Server.

SELECT * INTO NewTable FROM existingdb.dbo.existingtable;

如果数据库在两个不同的 SQL Server 上,有没有什么简单的方法可以做到这一点,而不必遍历原始表中的每条记录并将其插入到新表中?

Is there any easy way to do this if the databases are on two different SQL Servers, without having to loop through every record in the original table and insert it into the new table?

此外,这需要在 SQL Server Management Studio 之外的代码中完成.

Also, this needs to be done in code, outside of SQL Server Management Studio.

推荐答案

是的.添加链接服务器 条目,然后使用选择使用四部分 db 对象命名约定.

Yes. add a linked server entry, and use select into using the four part db object naming convention.

示例:

SELECT * INTO targetTable 
FROM [sourceserver].[sourcedatabase].[dbo].[sourceTable]

这篇关于将表复制到不同 SQL Server 上的不同数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆