0

In this first database design, column name starting from first_name to country exist in each table. The relationship of each table to table user_categories is ONE TO MANY.

enter image description here

In this second database design, there is no duplication of column name in each table. The relationship of table users and table shippers, suppliers, employees and customers are ONE TO ONE. Is the relationship correct?

The purpose of table shippers, suppliers, employees and customers is to store users based on its category in respective table just like the first design. I'm curious if this is a good practice since the columns of fourth tables is only its ID. Is there any column that I can add to those tables?

enter image description here

enter image description here

Could you please advice me if there are any better solutions?

1
  • Can you give me more specific answer if I explain that this database will use in online apps where user can be anyone in the world but a user can only choose one category for example, supplier. If he wants to change to customer, he must delete his account first. Since it will be used worldwide, the transaction will never stop. The basic idea of this database is how to manage four categories of users that have similar fields effectively and efficiently. Do you have any ideas about the performance of both design?
    – Xelonovia
    Commented Mar 26, 2019 at 13:37

1 Answer 1

1

In general. Recommended structure (assuming one user can fit into several categories):

users (user_id, 
       name, 
       -- etc., 
       primary key (user_id))

categories (cat_id, 
            category_type, -- shipper, supplier, etc.
            name, 
            -- etc., 
            primary key (cat_id))

users_to_categories (user_id, 
                     cat_id,  
                     -- etc.,
                     primary key (user_id, cat_id),  
                     foreign key (user_id) references users (user_id),  
                     foreign key (cat_id) references categories (cat_id))

If some user fits in more than one category there is more than one record in the last table with the same user_id and different cat_id.

A user can only choose one category for example, supplier. If he wants to change to customer, he must delete his account first.

If so:

users (user_id, 
       cat_id,
       name, 
       -- etc., 
       primary key (user_id),
       foreign key (cat_id) references categories (cat_id))

categories (cat_id, 
            category_type, -- shipper, supplier, etc., ENUM
            name, 
            -- etc., 
            primary key (cat_id))
2
  • A user can only choose one category for example, supplier. If he wants to change to customer, he must delete his account first.
    – Xelonovia
    Commented Mar 26, 2019 at 13:39
  • @Xelonovia This condition makes the structure more simple.
    – Akina
    Commented Mar 26, 2019 at 13:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.