0

What would be the correct way to normalize a scenario where we have Users and Roles where certain roles have the same attributes and other roles have different attributes? Let's take the following example:

tb_User(user_id, first_name, last_name, e_mail);

tb_Role(role_id, role)

tb_Plant(plant_id, plant)

tb_Entity(entity_id, entity)

I have roles like: Admin, General Manager and Plant Manager and Entity Manager. Admin and General Manager roles don't have any other attributes, but plant manager has a plant associated with it and Entity Manager has an entity associated with it. Should I create one table like this and have Plant/Entity have a value where it applies like this:

tb_user_role(user_role_id, user_id, role_id, plant_id, entity_id)

or have separate tables for plant and entity like this:

tb_user_role(user_role_id, user_id, role_id)

tb_user_role_entity(user_role_entity_id, user_role_id, entity_id)

tb_user_role_plant(user_role_plant_id, user_role_id, plant_id)

Another consideration is that one one user can have many plants, so one plant manager role and many plants, same thing for entity.

I appreciate your help,

Alex
  • 2,247
  • 1
  • 27
  • 37
  • What does this have to do with database normalization? – philipxy Jul 05 '18 at 22:33
  • Possible duplicate of [How can you represent inheritance in a database?](https://stackoverflow.com/questions/3579079/how-can-you-represent-inheritance-in-a-database) – philipxy Jul 05 '18 at 22:36
  • Hi. This is a faq. (Database/sql subtyping/inhertance/polymorphism. Also the antipattern multiple/many FKs to multiple/many tables.) Please always google many clear, concise & specific versions/phrasings of your question/problem/goal with & without your particular strings/names & read many answers. Add relevant keywords you discover to your searches. If you don't find an answer then post, using use one variant search for your title & keywords for your tags. – philipxy Jul 05 '18 at 22:38

0 Answers0