MySQL: Changing foreign key column - but keep data references intact -


i have problem concerning changing of foreign key reference , keeping data references intact.

i have 1 table containing comments, these comments created users, users stored in seperate table , referenced comments table foreign key. have lot of data in database, can't discard.

at first had made own login system unique id each user (their username - know, past me douche , didn't use integers ids), id referenced, , have changed users need facebook use page. problem lies - want comments foreign key changed facebook id instead of username, don't want loose data relation between comments , users.

i have following setup of tables , columns:

commentstable: [commentid] [comment] [userstable_username]  userstable: [userid] [(varchar) username] [(int) facebookid] 

what want instead:

commentstable: [commentid] [comment] [userstable_facebookid]  userstable: [userid] [(varchar) username] [(int) facebookid] 

i tried creating additional foreign key in commentstable - didn't keep relations.

i can't directly change pointer in commentstable point @ facebookid since 1 varchar , other int.

anyone has experience can out or give pointers?

i figured out workaround: using http://dev.mysql.com/doc/refman/5.0/en/update.html

update `table a`,`table b` set `table a`.`text`=concat_ws('',`table a`.`text`,`table b`.`b-num`," ",`table b`.`date`,'/') `table a`.`a-num` = `table b`.`a-num` 

so made column facebook id in comments table, used update query shown above (put in correct names of course).

afterwards deleted old [userstable_username] column in commentstable , made queries point facebookid column instead.


Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -