Pregunta

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

¿Fue útil?

Solución

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".

Otros consejos

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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top