What type of T-SQL data do you usually use for weight and length?

I am creating a table with several fields that will be used to record weight and length.
Examples: 5 kilograms and 50 grams will be stored as 5,050.
2 meters 25 centimeters will be stored as 2.25.

What T-SQL data type is best for them? Some calculation against these fields will be necessary, but using the default decimal (18.0) seems redundant.

+3
source share
4 answers

It depends on the range of values ​​that you intend to maintain. You must use a decimal value that covers this range.

, , , . , , 1000 , 7 , 3 - . (7,3)

+7

, . WeightInKilos, LengthInMetres

+7

, . 0,00 1000,00 . , 6 ( = 6), 2 ( = 2). decimal:

weight decimal(6,2)

() float real. , .

+2

, . , . . .

. harriyott , . - , , )

If these measurements are wide open and generally such that you need to support very large and very small numbers, perhaps the measurement can be divided into two columns. One to hold the value and one to hold the unit. One of the biggest glitches in this would be comparing values ​​if you need to find the heaviest objects, etc. This can be done using the lookup table, but, of course, adds a level of complexity.

0
source

Source: https://habr.com/ru/post/1722779/


All Articles