简体   繁体   中英

How to merge tables from 2 databases in SQL Server 2008

I'm using SQL Server 2008 - just a standard edition. Sorry if this is a rather basic question, but I know very little about SQL

I have 2 databases I've previously created using Visual Studio that would now benefit from being merged. By merged I mean copying the tables from the 2nd database to the first and deleting the 2nd database.

Is there a simple way of doing this through the SQL Management Studio?

You can use OPENROWSET to read data from one database and merge it into another.

For example:

USE DBToMergeInto;

INSERT INTO TableToMergeInto
SELECT * FROM OPENROWSET
    ('SQLOLEDB', 
     'Trusted_Connection=yes;Server=192.168.1.1\ServerToMergeFrom',
     'DbToMergeFrom.dbo.TableToMergeFrom')

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