Question

Based on performance, would it be better if two tables with 1:1 relationship has their column all merged into single table?

For example I have Users and Admins table. Admin shares all columns from Users but has its own specific columns like permission

so do I design the database like this (version A):

USERS         ADMINS
- id          - id
- username    - user_id
- password    - permission
- ...         - ...

or like this (version B)

USERS
- id
- username
- password
- permission (left empty when it's normal user)

Version A is cleaner but does version B is much faster? Which approach is more common?

Thanks

Was it helpful?

Solution

Cleaner solution should be given preference over faster hacks. However, in your case Admins seem to be only a role of the Users, not a separate entity. Merge the tables when as it is only a role that can be indicated by a column in the table. Use another table only when it is a separate entity.

So, in your case it should be "version B".

OTHER TIPS

In this case there is no need for another entity 'table' for Admins, Just add attribute 'Admin Permission' in USERS entity so Version B is the right one here.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top