Answer the question
In order to leave comments, you need to log in
How to split a table correctly?
There is a users table, I want to add rules (access to individual categories)
I.e. I have 2 options
1st option: add directly to the table
And then there will be users(user_id, user_hash, role_admin, role_moderator, role_submitter ...)
each role_* is a tinyint(1) type field where 1 or 0, because a person can be an admin and moderator, etc.
2.1 option:
add a rules table separately and make a primary key user_id
2.2 option
-//- and make a primary key rule_id and make the foreign key user_id and make it unique?
Which option would be better (and why (not necessarily, just for self-development))?
Sub-question:
If I want to make UUID keys, is it correct to do this:
user_id - int autocrement
user_hash - UUID key
And then, if accessed from outside, then by user_hash, and if inside the database, then by id
Is it correct to do this, or is it better to leave something alone?
Answer the question
In order to leave comments, you need to log in
Which option would be betterThe third.
make foreign key user_id and make it unique?and at the same time
maybe a person can be both an admin and a moderator, etc.will not work.
table user_has_role
user_id | role_id
------------------
1 | 1
2 | 1
2 | 7
select role_id from user_has_role where user_id = 2
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question