Nik
Nik

Reputation: 7273

SQL Server 2008 Query Between Databases

We are migrating database structures, so I have one database with the old structure and one database with the new structure (both on the same server). I want to write queries to copy data from one to the other. I am expecting to go table-by-table as the schema is different. How do I do this?

Upvotes: 0

Views: 758

Answers (3)

Chris Diver
Chris Diver

Reputation: 19812

You can write cross database queries like so

INSERT INTO NewDatabase.Schema.Table
SELECT Column1, Column2
FROM OldDatabase.Schema.Table

Upvotes: 1

JNK
JNK

Reputation: 65157

You need to provide more details to get a more specific answer, but in general you just use the three-part name:

INSERT INTO NewDB.dbo.TableName
SELECT <columns>
FROM OldDB.dbo.Tablename

Are you looking for a way to do this automatically for all the tables?

Upvotes: 3

Ashley John
Ashley John

Reputation: 2453

you can probably use Import data under tasks.Right Click the Target DB -> Tasks ->Import Data .You can also specify the source-> target mapping here.. and also write queries

Upvotes: 0

Related Questions