我正在尝试合并一些数据,但除了基础知识之外,我有点迷失。
我有这个..
INSERT INTO NewDB.Custs(Customer_ID) SELECT CustID FROM OldDB.Custs
移过这个我如何增加选择以添加更多?
这是我现在所拥有的基本布局。
OldDB =这是具有数据
的旧数据库
NewDB =数据进入的新数据库
|===========|==|===========|==|=============|==|===========|
|OldDB.Custs|..|NewDB.Custs|..|NewDB.Details|..|NewDB.Notes|
|===========|==|===========|==|=============|==|===========|
|CustomerID |>>|Customer_ID|>>|Customer_ID |>>|Customer_ID|
|CompanyName|>>|CompanyName|..|.............|..|...........|
|CFirstName |>>|FirstName |..|.............|..|...........|
|CLastName |>>|LastName |..|.............|..|...........|
|HowDidHear |>>|>>>>>>>>>>>|>>|HowHear_ID |..|...........|
|Notes |>>|>>>>>>>>>>>|>>|>>>>>>>>>>>>>|>>|CustNotes |
|Times |>>|>>>>>>>>>>>|>>|>>>>>>>>>>>>>|>>|NoteTime |
|Profession |>>|>>>>>>>>>>>|>>|Category_ID |..|...........|
|DefPmtMeth |>>|>>>>>>>>>>>|>>|DefaultPaymt |..|...........|
|Deactivated|>>|>>>>>>>>>>>|>>|Deactivated |..|...........|
|SalesRep |>>|>>>>>>>>>>>|>>|SalesRep_ID |..|...........|
|CertSent |>>|>>>>>>>>>>>|>>|CertSent |..|...........|
|===========|==|===========|==|=============|==|===========|
这是我正在尝试做的图。
有人能指出我正确的方向吗?
谢谢!
答案 0 :(得分:2)
一些经验丰富的SQL大师可能会以更好的方式进入,但你可以随时:
INSERT INTO NewDB.Custs (
Customer_ID, CompanyName, FirstName, LastName)
SELECT
CustomerID, CompanyName, CFirstName, CLastName
FROM OldDB.Custs
INSERT INTO NewDB.Details (
Customer_ID, HowHear_ID, Category_ID, DefaultPaymt, Deactivated,
SalesRep_ID, CertSent)
SELECT
CustomerID, HowDidHear, Profession, DefPmtMeth, Deactivated,
SalesRep, CertSent
FROM OldDB.Custs
INSERT INTO NewDB.Notes (
Customer_ID, CustNotes, NoteTime)
SELECT
CustomerID, Notes, Times
FROM OldDB.Custs