Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What T-SQL data type would you typically use for weight and length?

I am designing a table that has several fields that will be used to record weight and lengths.
Examples would be:
5 kilograms and 50 grams would be stored as 5.050.
2 metres 25 centimetres would be stored as 2.25.

What T-SQL data type would be best suited for these?
Some calculation against these fields will be required but using a default decimal(18,0) seems overkill.

like image 305
Andy Rose Avatar asked Dec 01 '22 06:12

Andy Rose


1 Answers

It really depends on the range of values you intend to support. You should use a decimal value that covers this range.

For example for the weight, it looks like you want three decimal places. Say you want the maximum to be 1000kg then you need a precision of 7 digits, 3 being behind the decimal point. This gives you decimal(7,3)

like image 195
Alex Deem Avatar answered Dec 04 '22 00:12

Alex Deem