开发者

SQL Server 2008 Query Between Databases

开发者 https://www.devze.com 2023-03-26 10:46 出处:网络
We are migrating database structures, so I have one database with the old structure and one database with the new structure开发者_如何学C (both on the same server). I want to write queries to copy dat

We are migrating database structures, so I have one database with the old structure and one database with the new structure开发者_如何学C (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?


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?


You can write cross database queries like so

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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消