简体   繁体   English

如何从不同MS SQL Server上托管的不同表中复制/合并数据,并将其保存到另一MS SQL Server上的一个表中

[英]How to Copy/Consolidate data from different tables hosted on different MS SQL Servers and save them into one Table on another MS SQL Server

I am a newbie in SQL so please bear with me. 我是SQL的新手,所以请多多包涵。 I am hoping you can help/guide me. 我希望你能帮助/指导我。 I have a table on 5 MS SQL Servers that have identical Columns and I want to consolidate the data into a separate table/separate MS SQL Server. 我在5个具有相同列的MS SQL Server上有一张表,我想将数据合并到一个单独的表/单独的MS SQL Server中。

the challenge is that I only have "Read Only Permission" from the source table (5 MS SQL Servers) but I have permission to create a table on the destination MS SQL Server DB. 挑战在于,我仅具有源表(5个MS SQL Server)中的“只读权限”,但是我有权在目标MS SQL Server DB上创建表。

another challenge is I wan to truncate or extract parts of the txt in one column of the source table and save them into different columns on the destination table. 另一个挑战是我想截断或提取源表的一列中的txt部分,并将它们保存到目标表的不同列中。

Next challenge is for the destination table to query once a day the source table for any update. 下一个挑战是目标表每天查询源表一次是否有更新。

See screenshot by clicking either of the URL. 单击任一URL查看屏幕快照。

Screenshot URL1 屏幕截图URL1

Screenshot URL2 屏幕截图URL2

Appreciate it very much if you can help/guide me. 如果您能帮助/指导我,请多加赞赏。 Many thanks in advance. 提前谢谢了。

You'll need to setup a linked server and use either an SSIS package to pull the data into the form you need, or OPENROWSET/OPENQUERY queries with an insert on the server you do have write privileges. 您将需要设置一个链接服务器,并使用SSIS包将数据提取到所需的表单中,或者在您具有写特权的服务器上插入一个OPENROWSET / OPENQUERY查询。

Either pre-create a table to put the new data in, or if not needed build up a temporary table or the insert the data into a table variable. 预先创建一个表以放入新数据,或者如果不需要,则建立一个临时表,或者将数据插入表变量中。

To concat a field to a new field use something like the examples below: 要将字段合并为新字段,请使用以下示例:

SELECT (field1 + field 2) as Newfield or SELECT (SUBSTRING(field1, 2,2) + SUBSTRING(field2, 3,1)) as Newfield SELECT(field1 + field 2)作为Newfield或SELECT(SUBSTRING(field1,2,2)+ SUBSTRING(field2,3,1))作为Newfield

Finally you should setup all this an agent Job scheduled to your needs. 最后,您应该根据您的需要设置所有这一切。

Apologies if this is not as detailed as you like, but it seems there are many questions to be answered and not enough detail to help further. 抱歉,没有提供您想要的详细信息,但似乎有很多问题需要解答,而细节不足以进一步帮助。

Alternatively you could also do a lookup upon lookup (USING SSIS): 另外,您也可以对查询进行查找(使用SSIS):

data flow task > download first table completely to destination server JOIN TO dataflow task > reading from destination server, do a lookup to 2 origin server (if match you might update, if not, insert) repeat until all 5 of them are done. 数据流任务>将第一个表完全下载到目标服务器加入数据流任务>从目标服务器读取,对2个原始服务器进行查找(如果匹配,则可能会更新,否则,请插入)重复执行,直到完成所有5个。

This is NOT the most elegant or efficient solution, but it will definitely get the work done. 这不是最优雅或最有效的解决方案,但绝对可以完成工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 MS SQL Server 2005将数据从一个表复制到另一个表 - MS SQL Server 2005 Copy data from one table to another 从一个表中复制数据并将其保存到不同SQL Server上不同数据库中的另一表中 - Copy data from one table and save it into another table in different database on different SQL Server 我想使用来自不同服务器(一个Sybase另一个MS)的SQL查询合并数据集 - I'd like to merge data sets using an SQL query from different servers (one Sybase the other MS) 使用查询MS SQL将一个表从一台服务器复制到另一台服务器 - Copy one table from a server to another server using query MS SQL 将数据从2列复制到另一个表中的1列MS SQL - Copy data from 2 columns in to 1 column in another table MS SQL MS SQL按行从另一个表复制数据 - MS SQL copy data from another table by rows MS SQL从另一个表中使用多个masterid和不同的childid更新一个表 - MS SQL Update one table from another table with multiple masterid and different childid 如何在 MS SQL Azure 中连接来自不同数据库的两个表? - How to join two tables from different database in MS SQL Azure? 将2 #temp表与来自不同服务器的数据连接在一起SQL Server - Joining 2 #temp tables with data from different servers SQL Server 将数据从 MS Access 复制到 SQL Server - Copy data from MS Access to SQL Server
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM