[thelist] MySQL: transfer data to table with different structure?

Frank lists at frankmarion.com
Sun Mar 9 14:54:07 CDT 2008


At 02:59 PM 2008-03-09, you wrote:
>I'm upgrading a client from a (very) previous version of a CMS that
>I've written to a newer version. I want to transfer their data over,
>but the table structures are slightly different. The tables and
>fields are essentially the same but have variation in naming schemes.


Interesting how things work. Yesterday I got some books out of 
storage thinking "This might come in handy". Lo and behold, Joe 
Selko's "SQL for Smarties: Advanced SQL Programming" Gave me the 
answer. And it's dead stupid simple (my favourite kind of answer). 
All one needs is one query per table.

INSERT INTO new_table (
   ArticleID
, ArticleTitle
, ArticleBody
, [... abreviated ...]
)

SELECT
   article_id
, article_title
, article_body
, [... abreviated ...]
FROM
database_name.old_table

Niiice.



Frank Marion     lists at frankmarion.com      Keep the signal high.






More information about the thelist mailing list