what is numeric(18, 0) in sql server 2008 r2

后端 未结 2 1417
遇见更好的自我
遇见更好的自我 2021-02-02 06:18

I found a table with this a column from this data type

numeric(18, 0)

what is that please? and why does 0 and 18 me

相关标签:
2条回答
  • 2021-02-02 06:33

    The first value is the precision and the second is the scale, so 18,0 is essentially 18 digits with 0 digits after the decimal place. If you had 18,2 for example, you would have 18 digits, two of which would come after the decimal...

    example of 18,2: 1234567890123456.12

    There is no functional difference between numeric and decimal, other that the name and I think I recall that numeric came first, as in an earlier version.

    And to answer, "can I add (-10) in that column?" - Yes, you can.

    0 讨论(0)
  • 2021-02-02 06:46

    This page explains it pretty well.

    As a numeric the allowable range that can be stored in that field is -10^38 +1 to 10^38 - 1.

    The first number in parentheses is the total number of digits that will be stored. Counting both sides of the decimal. In this case 18. So you could have a number with 18 digits before the decimal 18 digits after the decimal or some combination in between.

    The second number in parentheses is the total number of digits to be stored after the decimal. Since in this case the number is 0 that basically means only integers can be stored in this field.

    So the range that can be stored in this particular field is -(10^18 - 1) to (10^18 - 1)

    Or -999999999999999999 to 999999999999999999 Integers only

    0 讨论(0)
提交回复
热议问题