Should a value always be stored in a database using a specific unit (e.g. meters) or should the unit be settable using an additional field or table?
Example 1: Unit defined as part of the field
buildings
-----------------------------
building_id INT
date_built_utc DATE
reported_area_m DOUBLE
Example 2: Unit defined in another field
buildings
-----------------------------
building_id INT
date_built DATE
date_built_unit VARCHAR(50)
reported_area DOUBLE
reported_area_unit VARCHAR(50)
I am strongly leaning towards Example 1 because reporting on the values would be easier ( and less error prone ) if there is one standard unit for storing the data. The application layer can easily handle any conversions between units if the need arises.
Which method would be preferred and why?
I think allowing more than one unit would introduce a lot of confusion and maintenance headaches. Can you imagine someone reading 100 and thinking meters rather than feet? That's what caused the loss of a NASA orbiter, after all.
EDIT: What I mean is, by all means, if you can force a unit, do it. This will prevent any possible confusion over what the unit is.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With