Designing User & its Sub User Database Diagram Problem [duplicate]
-
16-03-2021 - |
سؤال
- There are some business category e.g. Travel Agency, Hotel, Car Rental etc.
- Roles:
- Management rolesSuper Admin, Staff
- Customer side roles are Owner, admin and sales counter
- May be etc. customer side roles will be added
- Status i.e. On-Hold, Active, In-Active, Blocked, Deleted etc.
- Scenario:
- Each user in the database has its role and status with other credentials
- Super Admin or Staff creates a customer (USER) with category e.g. "Travel Agency" and provide owner details
- Now this Travel Agency (USER) has its own SUB_USERS that may be one or many
Now I am confused between user and sub users.
The work that I done so far is as following in shape of ERD:
Please put me on the right path as to how can I create a USER with its SUB USERS?
Thanks in anticipation
المحلول
Why not just get rid of the main_user
and sub_user
tables and have a nullable field on the users
table called parent_user_id
. Then you can use a self-join on users.parent_user_id = users.user_id
to get all the sub-users for a given Travel Agency. (When the parent_user_id
field is null, that's a Travel Agency.)
لا تنتمي إلى dba.stackexchange