Monday, March 19, 2012

combine 3 databases

Combine 3 Databases, Not tables.

Let me spell this out -- I have 3 databases (they are in isolation when in use, its a field app) that need to be merged into 1 "masterDB" database. I've discovered I can use something like this to get to each DB in a query...

1 USE [database1]
2 SELECT table1.Name, table1.Location, table1.Date, table2.Blog
3 FROM table2INNERJOIN
4 table1ON table2.ID = table1.ID
5 ORDER BY table1.Date

and then just repeat for database2 and database3. Ok, fine, rah rah. My question is how do I "merge" all of these into 1. No data on each db will be identical, at all, ever so that is not a concern. I just need all the data from db1, 2 and 3 into masterDB.

Ideas? Direction?

CREATE VIEW vw_table1 AS

SELECT *

FROM database1.dbo.table1

UNION ALL

SELECT *

FROM database2.dbo.table1

UNION ALL
SELECT *

FROM database3.dbo.table1

|||

Knew it had to be something simple. Thanks!

No comments:

Post a Comment