If users can only be one type ...
Users โ UserTypes
The user table will have id_type, which will be the PK field in the UserTypes table.
Users
- userid 1
- name Jonathan Sampson
- email foo@bar.com
- typeid 1
UserTypes
- id 1
Type Unregistered
SELECT users.name, users.email, users.typeid, usertypes.type FROM users LEFT JOIN usertypes ON (usertypes.id = users.typeid) WHERE (users.id = 1)
Returns: Jonathan Sampson, foo@bar.com , 1, Unregistered
If users can be several types ...
Users -> UsersToTypes -> UserTypes
If the user must have a capacity of more than one type, you enter the third type:
UsersToTypes
So, if the user is both type1 (Customer) and type2 (President), you will have two entries in UserToTypes:
- userid (1 identifier for Jonathan Sampson)
- typeid (2 id for president)
- userid (1)
- typeid (1 identifier for the client)
Additional comments ...
I would not put the company name in the users / clients table. You will have such a name that exists many times if you have many of your representatives in your database. Instead, create a company table that stores the following data:
- Companyid
- The name of the company
- ContactNumber
- Streetaddress
- Town
- State
- Zipcode
Thus, if a company ever makes changes, you do not need to edit the customer table to update its name. You update your data in the corresponding table, and then globally update.
Of course, if you have several repetitions for each company, you need to create a RepsToCompanies table similar to our UsersToTypes.
Sampson
source share