简体   繁体   中英

Database design for many(few) to many(actually too many) relationship

I have two tables, user and programs. Now I have only, say, 5-10, programs and tens of thousands of users, who can be enrolled in any of the programs (can be enrolled in multiple programs too). So in a case of many to many relationship, I was thinking of creating a separate table, say link_user_program, to store which programs a user is enrolled in.

But if I have tens of thousands of user and just 10 programs, won't this consume extra space and increase query time than just storing the programs enrolled in the user table (maybe comma separated program ids or a boolean column for each program)?

What are the pros and cons of the above two designs or is there a better alternative? What if there's a situation that new programs may be added in the future (but still way considerably less than the number of users)?

From OO domain design perspective, recommend to use a many to many link table; forget about extra space, for query time, you can setup index to improve performance.

without link table, if will make you difficult to add/delete a problem in future.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM