B.S.
B.S.

Reputation: 21726

How to quickly import data between similar databases in SQL?

I use SQL Server.

There are 2 databases, old and the new one.

Databases relational structures are exactly the same.

The difference is:

  1. Some columns in one table are missing
  2. Some columns have different titles
  3. Some columns in a new one are added

The question is to find the way to import data from old database to a new one.

Upvotes: 1

Views: 631

Answers (2)

you can write a select into query, but consider eric's method first. I'm only adding this as an alternative.

USE AdventureWorks2008R2;
GO
SELECT c.FirstName, c.LastName, e.JobTitle, a.AddressLine1, a.City, 
    sp.Name AS [State/Province], a.PostalCode
INTO dbo.EmployeeAddresses
FROM Person.Person AS c
    JOIN HumanResources.Employee AS e 
    ON e.BusinessEntityID = c.BusinessEntityID
    JOIN Person.BusinessEntityAddress AS bea
    ON e.BusinessEntityID = bea.BusinessEntityID
    JOIN Person.Address AS a
    ON bea.AddressID = a.AddressID
    JOIN Person.StateProvince as sp 
    ON sp.StateProvinceID = a.StateProvinceID;
GO

reference: msdn

with "as" statements you would need to write the column names of the destination, so that the columns match.

Upvotes: 0

Eric
Eric

Reputation: 95133

Use the Import Data Wizard in SSMS to complete the task:

enter image description here

It'll walk you through the steps. You can read more here.

Upvotes: 5

Related Questions