database - MySQL CSV Row to multiple Rows -


i need migrate old database new one. unfortunately guy wrote old database created n,n relation using field comma separated foreign keys.

i write mysql query (maybe using insert ... select) splits comma seperated foreign keys can build table each row foreign key.

is possible?

it's not straightforward in pure sql. easiest retrieve each record in turn using programming language of choice , insert many-to-many join table records based on comma separated field. following pseudo code suggests approach might use:

for each (id, csv_foreign_keys) in source_rows     foreign_keys = split ',', csv_foreign_keys      each fk in foreign_keys         insert (id, fk) many-to-many link table 

once you've done this, existing column holding comma separated foreign keys can removed.


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -