Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Database design: 3 types of users, separate or one table? [closed]

I have 3 types of users:

  • Admins
  • Suppliers
  • Employees

Each user type will have different user interface and access different types of data. Their only similarity is they are using one web application but they access totally different things. Is it better to put them all in one user table like tbl_users or is it better to create tbl_admins, tbl_suppliers, tbl_employees?

like image 477
IMB Avatar asked Dec 12 '11 18:12

IMB


People also ask

What are the 3 table relationships in a database?

There are three types of relationships between the data you are likely to encounter at this stage in the design: one-to-one, one-to-many, and many-to-many. To be able to identify these relationships, you need to examine the data and have an understanding of what business rules apply to the data and tables.

What are the three types of database design?

Hierarchical database model. Relational model. Network model. Object-oriented database model.

What is a database with only one table called?

Flat file database. These databases consist of a single table of data that has no interrelation -- typically text files.


Video Answer


2 Answers

What you need to consider when designing tables is not necessarily what they'll have access to and how that is similar/dissimilar, but rather how the user levels themselves are similar/dissimilar.

For example, if the user types will have the same attributes (name, email, birthdate, etc), then they belong in one table together with a column indicating their privilege level.

This also facilitates changing privilege levels for a user, whereby you can make an ordinary Employee into an Admin, for example, by just updating the record in the user table.

If Suppliers are a different type of object with different attributes than the other two, Suppliers may belong in their own table.

Or, one more thing to consider: You might use a users table that holds only very limited information about users of all three types, and if the types have extended attributes that don't relate well to one another, you can store those in other tables with a foreign key back to the main users table.

like image 53
Michael Berkowski Avatar answered Oct 13 '22 08:10

Michael Berkowski


There is also a third choice: put the columns that all users have in common into tbl_users, and create three tables for tbl_admins, tbl_suppliers and tbl_employees joining to tbl_users as 1 to 0..1. You should consider this choice as an alternative when the number of shared columns is significant.

like image 30
Sergey Kalinichenko Avatar answered Oct 13 '22 07:10

Sergey Kalinichenko