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
Post a Comment