In my web application I will have three types of accounts.
Should all these three be in separate tables or in one with a column named "account_type" where i can mark it as User, Customer or Admin?
What are the pros and cons for both? Is there a best practice for this?
Thanks
In general, a person
can be user, customer and admin -- so, I would start with a Person
table with columns IsCustomer
, IsUser
, IsAdmin
. Later (for fast search) you may decide to add separate tables Admin
, Customers
, Users
with FK to the Person
table.
EDIT:
A typical case may be:
In general, having separate tables for customers and admins should speed-up any admin/customer related query.
If a user can only be one type, you'd be better off with one table and a bit field for IsAdministrator, etc.
If a user can be of more than one account type, you should then have a different table with a foreign key,
sample structure (data sypes are SQL Server and suggested only)
Users table
Roles table
User_Roles table
Pros and Cons vary based on the size and complexity of your system.
I would break it up into User, Role, UserResources
User (would define basic information)
User Roles
- FK->RoleType
Role_Type (user, admin, customer, possibly permissions or you could break this out further).
UserResources (media)
- FK->User
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With