How to manipulate databases across many SQL Servers
I currently 开发者_如何学JAVAhave four different servers all with many databases on them. Each server has between 1-4 databases/tables that I need consolidated on a different server and mapped to the columns in a table on that server.
As an example, lets say it was a user database I am creating on server D. The userId
is in a table in a DB in server A, the userName
is on server B, the dateUserStarted
is on server C (I know this is a stupid setup, its just for example)
Using SQL Server 2008 R2, how can I do this? I was also hoping to run a SQL Server Agent script that updated this merge table.
I've looked into "linked servers" and cannot seem to get it working. Is there something else I should be using?
Depending upon the frequency of reads, size of data, and bandwidth between servers, you might be able to get away with a remote join solution which is the easiest to maintain.
Create a db and view on server D that will join the three sources of data (userid, userName,dateUserStarted) from the other servers using Linked Servers. For example, server d will have three linked server objects called serverA, serverB, and ServerC.
Your View will look something like this. (I make some assumptions about remote table primary key being "Id").
Create view vUserData
as
SELECT A.userId, B.userName,C.dateUserStarted FROM [serverA].[TheDataBaseName].[dbo].[TableWithUserId] A
join [serverB].[TheDataBaseName].[dbo].[TableWithUserName] B on A.userId=B.id
join [serverC].[TheDataBaseName].[dbo].[TableWithDateUserStarted] C on A.userId=C.id
精彩评论