I have the following structure:
-- Table Users ---
- User1
- User2
- User3
-- Table Roles ---
- Role1
- Role2
- Role3
- Role4
Every user has to have one row, not more or less. Should i create a new table, eg. `user_roles” and store the users role in there, like:
-- Table user_roles --
- user_id = User1 role_id = Role2
- user_id = User2 role_id = Role1
- user_id = User3 role_id = Role4
Or, should I store the users role in the Users table? Since there will always only be one role for each user, I see no reason why not to keep it in the Users table. Am I thinking correctly or should it be in a separate table? Very simple question, but I’ve wondered for long. In the past I have kept the “key” in the Users table.
To enforce that every use has to have exactly one role, you should add a role_id to the users table, make it
not nulland reference the roles table