有没有在SQL Server decimal和numeric之间有什么区别?
-
09-09-2019 - |
题
是否有在SQL Server DECIMAL和数值数据类型之间的任何差异?
当应该使用DECIMAL并且当NUMERIC?
解决方案
它们是相同的。数字是功能上等同于小数。
MSDN:小数和数字
其他提示
这是什么然后SQL2003标准(第6.1节数据类型)表示关于两个:
<exact numeric type> ::=
NUMERIC [ <left paren> <precision> [ <comma> <scale> ] <right paren> ]
| DECIMAL [ <left paren> <precision> [ <comma> <scale> ] <right paren> ]
| DEC [ <left paren> <precision> [ <comma> <scale> ] <right paren> ]
| SMALLINT
| INTEGER
| INT
| BIGINT
...
21) NUMERIC specifies the data type
exact numeric, with the decimal
precision and scale specified by the
<precision> and <scale>.
22) DECIMAL specifies the data type
exact numeric, with the decimal scale
specified by the <scale> and the
implementation-defined decimal
precision equal to or greater than the
value of the specified <precision>.
要我所知有NUMERIC和DECIMAL数据类型之间没有差别。他们是同义的,彼此任何一个都可使用。 DECIMAL和NUMERIC数据类型是数字数据类型与固定精度和范围。
编辑:
说起几的同事也许它有事情做带有小数点是ANSI SQL标准和NUMERIC是一个喜欢的Mircosoft作为其编程语言中更常见。 ...也许;)
乔金姆贝克曼的回答是特定的,但是这可能带来额外的清晰度到它。
有一个微小的差别。按SQL傻瓜,第八版(2013):
DECIMAL数据类型类似于NUMERIC。 ......不同的是 您的实现可以指定精度比你更大 指定 - 如果是这样,将实现使用更高的精度。如果你 不指定精度或规模,实现使用默认 值,因为它与NUMERIC类型一样。
似乎上的差异的一些 SQL的实现方式是在数据的完整性。 DECIMAL允许从什么是基于一些系统默认,其中作为NUMERIC不限定溢出。
它们是同义词,在all.Decimal没有差别和数字数据类型与固定精度和范围数值数据类型。
-- Initialize a variable, give it a data type and an initial value
declare @myvar as decimal(18,8) or numeric(18,8)----- 9 bytes needed
-- Increse that the vaue by 1
set @myvar = 123456.7
--Retrieve that value
select @myvar as myVariable
它们是完全一样的。当你使用它是一致的。使用其中一个数据库中的
不隶属于 StackOverflow