使用 T-Sql,如何将远程服务器上的一个表插入到本地服务器上的另一个表中?
给定远程服务器“生产”(当前可通过 IP 访问)和本地数据库“开发”,如何使用 T-SQL 从“生产”运行 INSERT
到“开发”?
我使用的是 MS SQL 2005,两个数据库之间的表结构有很大不同,因此我需要手动编写一些迁移脚本。
更新:
T-SQL 确实不是我的菜。我尝试了以下操作(不知道我在做什么):
EXEC sp_addlinkedserver
@server = N'20.0.0.1\SQLEXPRESS',
@srvproduct=N'SQL Server' ;
GO
EXEC sp_addlinkedsrvlogin '20.0.0.1\SQLEXPRESS', 'false',
'Domain\Administrator', 'sa', 'saPassword'
SELECT * FROM [20.0.0.1\SQLEXPRESS].[DatabaseName].[dbo].[Table]
并且出现错误:
用户“”登录失败。用户是 不与受信任的 SQL 关联 服务器连接。
Given the remote server 'Production' (currently accessible via an IP) and the local database 'Development', how can I run an INSERT
into 'Development' from 'Production' using T-SQL?
I'm using MS SQL 2005 and the table structures are a lot different between the two databases hence the need for me to manually write some migration scripts.
UPDATE:
T-SQL really isn't my bag. I've tried the following (not knowing what I'm doing):
EXEC sp_addlinkedserver
@server = N'20.0.0.1\SQLEXPRESS',
@srvproduct=N'SQL Server' ;
GO
EXEC sp_addlinkedsrvlogin '20.0.0.1\SQLEXPRESS', 'false',
'Domain\Administrator', 'sa', 'saPassword'
SELECT * FROM [20.0.0.1\SQLEXPRESS].[DatabaseName].[dbo].[Table]
And I get the error:
Login failed for user ''. The user is
not associated with a trusted SQL
Server connection.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
创建一个 链接服务器,然后使用 4 部分表示法,
您也可以使用 < href="http://msdn.microsoft.com/en-us/library/ms190312.aspx" rel="nofollow">OPENROWSET
示例
尝试使用此方法创建登录名
create a linked server and then use 4 part notation
you can also use OPENROWSET
example
try this to create the login
您可以将 PROD 服务器定义为 DEV 框的链接服务器,然后访问它。
不过,我认为从 PROD Box 获取备份并将其恢复到 DEV 或使用 SSIS 进行架构导入会更容易。
You can define the PROD Server as Linked Server to the DEV box and then access it.
However I think it would be easier to get a backup from PROD Box and Restore it to DEV or use SSIS for Schema Import.
查看 RedGate 工具,尤其是。 SQL 数据比较。如果这不是一个选项,您应该查看 OPENDATASOURCE 或 OPENROWSET 访问远程数据库。
Look into the RedGate tools, esp. SQL Data Compare. If that's not an option you should look at OPENDATASOURCE or OPENROWSET to access the remote database.
那么您可以使用链接服务器,然后使用对象的 4 个部分名称(有关如何设置链接服务器的信息,请参阅 BOL)
或者您可以使用 SSIS 设置数据迁移并连接到远程服务器
或者您可以使用 OPENROWSET
我可能会使用 SSIS,但我已经熟悉它了。
Well you can use a linked server and then use the 4 part names for objects (See BOL for how to set up a linked server)
Or you could use SSIS to set up the data migrations and connect to the remote server
Or you could use OPENROWSET
I'd probably use SSIS, but I'm already familiar with it.
使用SSMS。右键单击目标数据库并选择“任务”、“导入数据”。您将能够预览数据并直观地进行转换。将包保存在 SSIS 中或立即运行。
Use SSMS. Right click on the target DB and select "Tasks", "Import Data". You will be able to preview the data and make conversions visually. Save the package in SSIS or run it now.