P
P
Phoen1xx2019-11-07 19:30:34
MySQL
Phoen1xx, 2019-11-07 19:30:34

How to store the data of different users in the database?

Hello. I have users on the site with different roles (administrator, moderator, user). All of them are in the same "users" table, but since each of them has its own data, for example, the user has a full name and phone number, but the administrator does not have these fields, I had to create a fairly large database which now looks something like this:

+----------------+------------+-----------+-------------+----------+--------+
|      email     | first_name | last_name | second_name | password |  role  |
+----------------+------------+-----------+-------------+----------+--------+
| [email protected] | NULL       | NULL      | NULL        | ...      | admin  |
| [email protected]   | FName      | LName     | SName       | password | user   |
+----------------+------------+-----------+-------------+----------+--------+

This results in too many columns. several roles. How should it be stored properly?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
E
Eugene, 2019-11-07
@Nc_Soft

Make separate tables, these are different entities.

I
Ivan Melnikov, 2019-11-07
@immelnikoff

What about role-based access control (RBAC) model?
Entities such as resource, action, user, and role are separated into separate relationships. They are connected by plates of the form M:N.

K
Kirill Gorelov, 2019-11-07
@Kirill-Gorelov

Don't worry, normal database.
Look at the structure of the Bitrix database. It does not matter what types of users, the fields are the same for everyone. And even more so the standard for sure. Type password, group, name, etc.
Even in different frameworks, the structure of the user table is the same, with slight differences, of course. But the essence is the same.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question