I’m trying to understand how to design a database that can accommodate an indeterminate number of fields per User.
For example, User1 is involved in Projects A, B and C. User2 is involved in Projects A, C, E and G while User3 is involved in Projects A, B, C, D, E, F and G.
A table with Users listed in rows and then 7 more columns to record the Projects they’re involved in would serve quite nicely… until I have to accommodate User4 who winds up being involved in 100 projects, which, in my model, would require 100 columns for keeping track.
There would ultimately be no way of knowing in advance how many columns to define.
I could flip it around and associate User1 & User3 with Project B, but then further on down the road, after there are 10,000 Projects, I’d have to look through each Project record to produce a complete list of Projects that a given User has been involved in, which seems terribly inefficient.
So… how to keep track? Just can’t quite wrap my head around this one.
Am total newbie, so forgive me if this is poorly stated or grossly elementary.
Thanks,
Ben
It sounds like you may be trying to mix these two entities (
userandproject) into a single table, which really isn’t the best way to go.A different approach is to have your user info in a
usertable, project info in aprojecttable, and another “link” table likeuser_projects, which would just contain the ID fields from theuserandprojecttables, one entry for each user in each project.an example schema:
To select project titles for user 3, you could do something like:
The point of the
user_projectstable is to link the information contained in theuserandprojecttables, that is all.