Database design: 4 types of users but have different functionality , separate or one table?

I have 4 types of users:

Admins ,
normal user ,
company ,
service provider

admins and normal user share some attributes (id .first name ,last name ,phone ,mail)
company and service provider share some attributes too (id .company name ,phone ,fax ,mail )

and they interact too with other entities in application to access some feature like post job or event or apply for it

Is it better to put them all in one user table like tbl_users or is it better to create separate table to every one ? or add to two tables one for (Admins and normal user) and other for ( company and service provider)

and this is some details about the entity attributes.

enter image description here

What you expose depends highly on your application needs.

One typically do dissociate users from contact informations allowing maximum flexibility. I’d recommend also to factorize the contact informations data into a single table.

User (1,1) — (0,1) Contact_Information

Company (1,1) — (0,1) Contact_Information

Service Provider (1,1) — (0,1) Contact_Information

The user table would include login data and an addition is_admin field. The existence of a link between two entities would also let you the flexibility such a “real person” can represent both a normal user and a company.

I’d also recommend you to read about how to model inheritance in a database -> https://stackoverflow.com/questions/190296/how-do-you-effectively-model-inheritance-in-a-database

I’d keep them all in one table, and add a field to indicate what type of user it is. You’ll have some blank fields (for example admins and normal users don’t have fax numbers) but this shouldn’t be an issue unless you have lots and lots of users and some fields are only used for a very small proportion of them. You could also fill in the blanks since there’s no reason why normal users can’t have a fax number, or why service providers can’t have first and last names.

If necessary you could have a “users” table and a “user attributes” table but it’s probably not worth it for a small number (i.e. a few hundred) users.

1

Unless the different user types really have different roles in the schema, keep them in one table. I would have fields such as the following:

  • User type (user, admin, company, provider)
  • First and last name
  • Company name

It may even make sense to separate the phone numbers and addresses into other tables, to allow one user to have many phone numbers and addresses (perhaps a company has multiple offices, a user has home, cell, work numbers, etc) although this is technically not part of the question.

The important thing to remember is that a user type is easily represented as a field on a table, allowing other tables to point to any user: this enforces a single relationship type. Furthermore, users can change types without needing to map data between tables, update foreign keys, etc. What if a normal user becomes an admin? What if he is working out of his home and incorporates, maybe hires an additional worker? It is quite feasible for users to change types in the real world, your business rules may be different of course.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa

Database design: 4 types of users but have different functionality , separate or one table?

I have 4 types of users:

Admins ,
normal user ,
company ,
service provider

admins and normal user share some attributes (id .first name ,last name ,phone ,mail)
company and service provider share some attributes too (id .company name ,phone ,fax ,mail )

and they interact too with other entities in application to access some feature like post job or event or apply for it

Is it better to put them all in one user table like tbl_users or is it better to create separate table to every one ? or add to two tables one for (Admins and normal user) and other for ( company and service provider)

and this is some details about the entity attributes.

enter image description here

What you expose depends highly on your application needs.

One typically do dissociate users from contact informations allowing maximum flexibility. I’d recommend also to factorize the contact informations data into a single table.

User (1,1) — (0,1) Contact_Information

Company (1,1) — (0,1) Contact_Information

Service Provider (1,1) — (0,1) Contact_Information

The user table would include login data and an addition is_admin field. The existence of a link between two entities would also let you the flexibility such a “real person” can represent both a normal user and a company.

I’d also recommend you to read about how to model inheritance in a database -> https://stackoverflow.com/questions/190296/how-do-you-effectively-model-inheritance-in-a-database

I’d keep them all in one table, and add a field to indicate what type of user it is. You’ll have some blank fields (for example admins and normal users don’t have fax numbers) but this shouldn’t be an issue unless you have lots and lots of users and some fields are only used for a very small proportion of them. You could also fill in the blanks since there’s no reason why normal users can’t have a fax number, or why service providers can’t have first and last names.

If necessary you could have a “users” table and a “user attributes” table but it’s probably not worth it for a small number (i.e. a few hundred) users.

1

Unless the different user types really have different roles in the schema, keep them in one table. I would have fields such as the following:

  • User type (user, admin, company, provider)
  • First and last name
  • Company name

It may even make sense to separate the phone numbers and addresses into other tables, to allow one user to have many phone numbers and addresses (perhaps a company has multiple offices, a user has home, cell, work numbers, etc) although this is technically not part of the question.

The important thing to remember is that a user type is easily represented as a field on a table, allowing other tables to point to any user: this enforces a single relationship type. Furthermore, users can change types without needing to map data between tables, update foreign keys, etc. What if a normal user becomes an admin? What if he is working out of his home and incorporates, maybe hires an additional worker? It is quite feasible for users to change types in the real world, your business rules may be different of course.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật