I’d like to store additional data if a particular value is chosen in the enumerated or looked-up column in a table. The obvious option is to have an extra column in the table, but this will lead to a mostly empty column and seems to be like bad approach. Is there another option/method of doing this?
Share
The cleaner approach would be to have another table containing the mapping between rows in the original table and the optional values. For example, say you are storing employee records, so you have a table with 4 columns: Id, Name, Department, and SalesQuota. Now, the SalesQuota value is filled in only for rows where Department = “Sales”.
Separate the table, so that you have your employee table with Id, Name, and Department, and a sales quota table with Id and SalesQuota. You can join the two tables on id, to get the original view, but at the same time, you don’t have a mostly-empty column. You can join the two tables, or operate on each separately.
Search for “database normalization” online to get lots more articles on this topic.