Should we always abbreviate column values like for the category column?


#1

Question

In this code challenge, the category column values are abbreviated as ‘b’ for ‘Business’ and ‘t’ for ‘Technology’. Should we always abbreviate column values like the category column?

Answer

This can be entirely dependent on how you choose to implement the table, and there is no right or wrong answer.

To decide whether to use abbreviations for values, you might consider a few of the following factors.

One important factor is understandability of the information. What if it was not apparent immediately that 'b' stood for ‘Business’, and 't' for 'Technology? To account for this, you may need to store the abbreviation meanings somewhere easily accessible, like another table in the database with abbreviations mapped to their full meanings. Also, what if there were multiple values that started with b, like Books? You might need to choose some way to represent any possible values as abbreviations.

Another factor you might consider is memory. Using abbreviations can have the benefit of saving memory used. For instance, the column data type can be set to some smaller data type like CHAR, which can take less memory than the TEXT data type. When you have millions, or even billions, of entries, these values start to really add up.

Everything has a tradeoff, so whichever method you choose can have some pros and cons that might be more appropriate to your needs.