Migrating SQL data from Access
I need to migrate some data from access t开发者_StackOverflow中文版o sql.
access has one table: tblMakeModel with two fields: make, model
I am making two tables in SQL
- tblMake: id, make
and
- tblModel: id, makeID, model
I've moved the makes over, but now i can't figure out how to migrate the models to match up with the makeIDs, since I am recreating ID's, how do i match them up?
please help
(I'm assuming that the IDs are database-generated integers).
Bring the entire table into the SQL Server database and call it tblMakeModel (just like in the original). Then:
INSERT INTO tblMake (Make) SELECT DISTINCT Make FROM tblMakeModel
INSERT INTO tblModel (MakeID, Model)
SELECT DISTINCT M.MakeID, MM.Model
FROM tblMakeModel MM INNER JOIN tblMake M ON MM.Make = M.Make
DROP TABLE tblMakeModel
If the IDs are not a sequence, then you'll need to edit the tblMake table after the first command to contain the new IDs and then run the other two commands, then add the IDs to the tblModel table. In this case, you'll need to remove the PK constraint on both tables until you finish your work.
精彩评论