I need to transform some data between two different database schemas. For example, I have one table in old schema like this:
and I need to transform it to new schema like this:
So I have few questions to ask:
- Does there exist software that can migrate data between these two schemas (Without or with little usage of SQL)?
- If it exists, can this software migrate even between two platforms (i.e. MS SQL Server to Oracle)?
Thanks!
Best Answer
You'll need to use a multi-database tool - I would recommend SQuirreL SQL - it's a Java based tool that connects through JDBC. If you want to migrate to Oracle, you could also consider SQL Developer (which IIRC can connect to MS SQL through JDBC also).
As @ConcernedOfTunbridgeWells said in his comment, you can't get a "push-button" migration of data - you have to explicitly tell the different systems from what column they're to take data and where to put it and join the tables back and forth. If it could be done automatically, there'd be no need for programmers or
DBA
s :-).I've used the script below for PostgreSQL to solve your problem. For simplicity, I haven't put in
PRIMARY KEY
s,FOREIGN KEY
s orINDEX
es which may (probably) help with performance.1st I created the employee table and put a small amount of sample data into it.
Below is not strictly necessary - but it's always a good idea to "eyeball" your data, particularly when testing!
Create the new table city.
Now, insert into this new city table, the
DISTINCT
values from the city field in your employee table.And again, to double-check.
Add a column city_id to the employee table.
You can select again from the table to double-check (step skipped for brevity).
Next, you have to update the employee table with the corresponding id value that you've created in the new city table. The syntax for this step may vary according to your RDBMS - I found this post helpful.
Drop the city column from the employee table. Again, step may vary.
Result - et voila!