[英]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查看屏幕快照。
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.