How to store unit quantity and type in MySQL?

I'm not really sure how to articulate this question. So please point me in the right direction if this has already been answered.

Basically I want to store the unit types so that I can do some comparison later based on user selection. For example, user can select "day", "week", "month", "year" as a unit type. Then they need to select a number associated to that unit type. Having this number and the unit type will allow my program to do some calculation based on user selection.

Another example is for selecting other unit types like metrics and imperial that is, mm, cm, m, km, or inch, feet, mile, etc etc...

Do I just store them as varchar and then just do a string comparison in my program?


Varchar is always the option of last resort. Try and create a numbering system for it like with ids. So, you could have another table for relationships that would have the text value like "day","month", etc matching the numbering system.

Need Your Help

Rename table data field in mysql


Chart_date chart_field chart_counts

Is there a way to make hibernate throw an exception for an unmapped class?

hibernate hibernate-mapping

Hibernate's use of implicit polymorphism means that when you have a query (Criteria in my case) explicitly associated with a class for which there is no hibernate mapping, it fails silently (return...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.