My application has a database table that is used to record the attendance of employees. And the column attedance_status
has only three possible values - "present"
, "absent"
, "on_leave"
, and NULL
as default.
How do I add it to the database? So far I have come up with two possible ways.
Create another table attendance_status
with status_id
and status_value
and add the above values to it. And then use the id in the application for all SQL queries.
Probably the bad way. Hardcode the values (maybe in a config file) and use it throughout the app's SQL queries.
Am I missing the right way? How should this be approached?
Either will work, but Option 1 will give you flexibility in the event that the requirements change and is the standard data model. I would, however, name my columns a little differently. I would have id
, value
, name
. Then the references become attendance_status.id
and attendance_status.value
. The third column is available for use in displays or reports or whatever. value
is on_leave
and name
is On leave
.
Option 2 works provided the data input point is totally closed. If someone codes new functionality there is the risk that he or she will invent something different to mean the same thing like onLeave
.