views:

286

answers:

6

I need to convert data that already exists in a MySQL database, to a SQL Server database.

The caveat here is that the old database was poorly designed, but the new one is in a proper 3N form. Does any one have any tips on how to go about doing this? I have SSMS 2005.

  1. Can I use this to connect to the MySQL DB and create a DTS? Or do I need to use SSIS?
  2. Do I need to script out the MySQL DB and alter every statement to "insert" into the SQL Server DB?

Has anyone gone through this before? Please HELP!!!

A: 

What you need is an ETL (extract, transform, load) tool.

http://en.wikipedia.org/wiki/Extract,_transform,_load#Tools

codeelegance
A: 

I don't really know how far an 'ETL' tool will get you depending on the original and new database designs. In my career I've had to do more than a few data migrations and we usually always had to design a special utility which would update a fresh database with records from the old database, and yes we coded it complete with all the update/insert statements that would transform data.

I don't know how many tables your database has, but if they are not too many then you could consider going the grunt root. That's one technique that's guaranteed to work after all.

Cyril Gupta
+2  A: 

See this link. The idea is to add your MySQL database as a linked server in SQL Server via the MySQL ODBC driver. Then you can perform any operations you like on the MySQL database via SSMS, including copying data into SQL Server.

Congrats on moving up in the RDBMS world!

David Lively
Some would disagree that MSSQL is a step up from MySQL. :D
codeelegance
Definitely the easiest way to go. Works for getting data into Access as well (assumes anyone ever would want to do that).
Tom
@Kenneth: I thought the same thing at first, but I think he means moving from bad design to normalization.
Tom
I know but I just couldn't resist.
codeelegance
A: 

I have done this going the other direction and SSIS works fine, although I might have needed to use a script task to deal with slight data type weirdness. SSIS does ETL.

Andy West
A: 

If you go to your database in SSMS and right-click, under tasks should be an option for "Import Data". You can try to use that. It's basically just a wizard that creates an SSIS package for you, which it can then either run for you automatically or which you can save and then alter as needed.

The big issue is how you need to transform the data. This goes into a lot of specifics which you don't include (and which are probably too numerous for you to include here anyway).

I'm certain that SSIS can handle whatever transformations you need to do to change it from the old format to the new. An alternative though would be to just import the tables into MS SQL as-is into staging tables, then use SQL code to transform the data into the 3NF tables. It's all a matter of what your most comfortable with. If you go the second route, then the import process that I mentioned above in SSMS could be used. It will even create the destination tables for you. Just be sure that you give them unique names, maybe prefixing them with "STG_" or something.

Davud mentioned linked servers. That's definitely another way that you can go (and got my upvote). Personally, I prefer to copy the tables over into MS SQL first since linked servers can sometimes have weirdness, especially when it comes to data types not mapping between different providers. Having the tables all in MS SQL will also probably be a bit faster and saves time if you have to rerun or correct portions of the data. As I said though, the linked server method would probably be fine too.

Tom H.
+2  A: 

SSIS is designed to do this kind of thing. The first step is to map out manually where each piece of data will go in the new structure. So your old table had four fields, in your new structure fileds1 and 2 go to table a and field three and four go to table b, but you also need to have the autogenerated id from table a. Make notes as to where data types have changed and you may need to make adjustments or where you have required fileds where the data was not required before etc.

What I usually do is create staging tables. Put the data in the denormalized form in one staging table and then move to normalized staging tables and do the clean up there and add the new ids as soon as you have them to the staging tables. One thing you will need to do if you are moving from a denormalized database to a normalized one is that you will need to eliminate the duplicates from the parent tables before inserting them into the actual production tables. You may also need to do dataclean up as there may be required fileds in the new structure that were not required in the old or data converstion issues becasue of moving to better datatypes (for instance if you stored dates in the old database in varchar fields but properly move to datetime in the new db, you may have some records which don't have valid dates.

ANother issue you need to think about is how you will convert from the old record ids to the new ones.

This is not a an easy task, but it is doable if you take your time and work methodically. Now is not the time to try shortcuts.

HLGEM
"SSIS is designed to do this kind of thing." - Exactly. :)
Andy West