简体   繁体   中英

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. 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.

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.

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.

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.

Screenshot URL1

Screenshot 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.

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

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):

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.

This is NOT the most elegant or efficient solution, but it will definitely get the work done.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM