Skip to content
Advertisement

Should I create a separate table in MySQL when I have fixed number of possible values for a field?

I’m doing some database optimization and I was wandering, if I have a table Users, and that table has a _status field, should I be creating a separate table for status codes like so:

Table statuses:
    _status_id: PK int(16) Ai,
    _status_name: varchar(32)

and then have a status_code_id field in the Users table that links to the _status_id field of the statuses table, or just write the _status_name directly in the User?

I should note that there are fixed number of statuses, and i do not plan to add any additional data regarding the status like status description or status code or something like that. Its always going to be 4 statuses – active, inactive, away, busy.

I think that if im doing some sort of get by status query, it will take longer if they are separated into 2 tables then it would if it was all in one table.

Advertisement

Answer

It depends from the case:

Does this status is important in your application? Is it used in many logics? Then it should have a separate table, as it will reduce the hardcoding in the application.

On a theoretical level also should be a separate table, as it represents a well defined entity. (IMHO)

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement