MySQL structure for large number of fields -


i have mysql database 1 table stores user information , table stores called 'tags' each user. structure this:

table 1: user_info

id | col1 | col2 | .... 

table 2: tags

id | user_id | tag 

the approximate number of users around 25000, , practically speaking each user have 50 tags theoretically user can create infinite tags. each user can access tags he/she created, paired user_id in table 2.

so question is structure have structure, or there better way this? (let me know if not right place ask, since not direct code question.)

you make tags table , relationship table relate users table tags table. have many-many relationship between users , tags through relationships table.

a tag table: id, name, etc. user table: id, name, etc. relationship table: user_id, tag_id, foreign keys tied tag.id , user.id, , pk on tag.id , user.id.

as far know that's best way it, you'll have 1 row each tag, 1 row each user, , table row each relationship between user , tag.

depending on you're using app side, can neat relationships between models - many-many-through scenario in active record or similar, , make things easy on yourself.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -