views:

57

answers:

2

We are planning to capture a user's height and weight and am looking for ideas on representing them in sql. I have the following questions in mind

  1. weight can be expressed in kilograms and grams and height in meters and centimeters, so should I capture them as a BigDecimal with an appropriate precision and scale or capture them as vanilla strings and do the manipulation in the user interface. Note: I am planning to capture the kilograms and grams separately in the user interface.

  2. should the metric of measurement be part of the sql (i.e. the end user might want to view this information in pounds, inches according to his preference)

OR

Should I just support kilograms / meters in the database and do the conversion while showing this in the user interface

+2  A: 

For the first question, I would recommend you use integers and the smallest unit of record (centi-meters and grams for example). Only store one format in the database and do the conversion from within your application.

Kevin Sylvestre
+1  A: 

I would store height in centimeters and weight in grams and then perform any desired conversions in the user interface. This allows for easy calculations in the database if you ever have to perform any aggregate queries (e.g. AVG to determine average weight across a set of users).

mcliedtk