Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it good database design to have admin users in the same table as front-end users?

I have users who can login on a front-end page, and admins who can login on an admin page.

Should both users and admins be "Users" with different roles, or should they be split in different tables?

like image 211
Steven Avatar asked Nov 12 '10 23:11

Steven


People also ask

What is the most important design feature when designing a database?

A good database design is, therefore, one that: Divides your information into subject-based tables to reduce redundant data. Provides Access with the information it requires to join the information in the tables together as needed.

When designing a database Why is it not preferable to store all data in one table?

Answer and Explanation: Storing all data in one single table will be confusing, may have security issues and there will be duplication in recording.


2 Answers

Roles should be tracked separately from user accounts, because someone can be promoted (or demoted) over time. Would it make sense in that situation to have two different user accounts, in two different tables? I think not.

Here's the basic structure I'd use -

USERS

  • user_id (primary key)
  • user_name

ROLES

  • role_id (primary key)
  • role_name

USER_ROLES

  • user_id (primary key, foreign key to USERS.user_id)
  • role_id (primary key, foreign key to ROLES.role_id)
like image 142
OMG Ponies Avatar answered Sep 20 '22 00:09

OMG Ponies


Yes, all users belong in the users table. You also need to have a Roles table and have a FK betweent the two.

like image 31
Esteban Araya Avatar answered Sep 20 '22 00:09

Esteban Araya