My database model has 2 particular tables in it that require a many-to-many relationship. The tables are Systems and Users. One user can be a member of more than one system and one system has more than one user in it.
system_id is the PK in the system table and user_id is the PK in the user table. I have them linked with system_id as a FK in the user table. I can’t seem to figure out a table in between the two. I had the notion of forming a system_user table and using both foreign keys in there but cant see how that would work.
You’re headed in the right direction.
Create a table ‘system_user’:
This is not properly an entity in a strict relational modelling sense, so it doesn’t require a primary key. However, you can add one if your scenarios require it.
To get all of the users in a system you’d query like so:
To get all of the systems a user can reach, you’d query like so:
Hope this helps!