什么是 sql server 2008 r2 中的 numeric(18, 0)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25190976/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 02:24:55  来源:igfitidea点击:

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

sqlsql-serversql-server-2008-r2

提问by Agnieszka Polec

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

我从这个数据类型中找到了一个带有这个列的表

numeric(18, 0)

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

请问那是什么?为什么是018意思

I already check this question Difference between numeric, float and decimal in SQL Serverbut couldn't understand it.\

我已经检查了这个问题SQL Server 中数字、浮点数和小数之间的区别,但无法理解。\

can I add (-10) in that column?

我可以在该列中添加 (-10) 吗?

can I add all negative number in that column?

我可以在该列中添加所有负数吗?

can I add any positive number in that column?

我可以在该列中添加任何正数吗?

Update 1

更新 1

This is a sample of the data I found in that column

这是我在该列中找到的数据示例

100
263
13
2
9
4
3
3
28
15
33
16
135
50
64
60
100
500
150

Update 2 Is it possible to have -and +?

更新 2 是否有可能有-+

回答by christiandev

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

的第一个值是精确和第二个是规模,所以18,0基本上是18位数字与小数点后0数字。18,2例如,如果您有,您将有 18 位数字,其中两位将出现在小数点之后......

example of 18,2: 1234567890123456.12

18,2 的例子:1234567890123456.12

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

和之间没有功能上的区别,除了名称之外,我想我记得数字在前,就像在早期版本中一样。numericdecimal

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

并回答“我可以在该列中添加 (-10) 吗?” - 是的,可以。

回答by Dan

This pageexplains it pretty well.

这个页面很好地解释了它。

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

作为numeric可以存储在该字段中的允许范围是-10^38 +1to 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.

括号中的第一个数字是将存储的总位数。计算小数点的两边。在这种情况下是 18。所以你可以有一个小数点前 18 位数字、小数点后 18 位数字或两者之间的某种组合。

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.

括号中的第二个数字是小数点后要存储的总位数。因为在这种情况下数字是 0,这基本上意味着这个字段中只能存储整数。

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

这样可以存储在这一特定领域的范围是-(10^18 - 1)(10^18 - 1)

Or -999999999999999999to 999999999999999999Integers only

-999999999999999999999999999999999999整数只