在创建“精度浮动"类型的表列时列被创建为“真实的"键入 SQL 服务器 [英] On creating a table column of type "float with precision" column gets created as "real" type in SQL server
问题描述
我创建了一个简单的表格,如下所示:
I created a simple table as below:
create table table1
(
col1 float(1),
col2 float
)
当我使用 sp_help 或脚本表作为创建检查表定义时,我得到的 float(1) 是真实的
When I check the table definition using sp_help or script table as create, I get the float(1) as real
CREATE TABLE [dbo].[table1](
[col1] [real] NULL,
[col2] [float] NULL
)
根据我对 msdn 和 stackoverflow 引用,float 的精度 n 可以从 1 到 53.
As per my understanding from msdn and stackoverflow references, float can have a precision n ranging from 1 to 53.
为什么当 float 指定了精度时,默认情况下它会转换为 real?
Why is it getting converted to real by default whenever float has a precision specified?
推荐答案
SQL Server 不记得您创建表时使用的语言 - 它只是查询当前表定义并呈现一段文本可以用于创建相同的表.
SQL Server doesn't remember what language you used when you create the table - it just consults the current table definition and renders a piece of text that could have been used to create an identical table.
正如 文档 指出的那样,SQL Server 没有支持任意精度 - 它只支持两个精度 - 24 和 53:
As the documentation points out, SQL Server doesn't support arbitrary precisions - it only supports two precisions - 24 and 53:
SQL Server 将 n
视为两个可能值之一.如果 1<=n<=24,n
被视为 24.如果 25<=n<=53,n
被视为 53.
SQL Server treats
n
as one of two possible values. If 1<=n<=24,n
is treated as 24. If 25<=n<=53,n
is treated as 53.
正如它还指出的那样,real
被视为 float(24)
的同义词:
As it also points out, real
is treated as a synonym for float(24)
:
real 的 ISO 同义词是 float(24).
The ISO synonym for real is float(24).
因此,任何指定精度为 24 或更低的浮点列实际上都将创建为 float(24)
.float(24)
的同义词是 real
.系统不记得它最初是指定为 float(1)
、float(24)
还是 real
.
So, any float column specified with a precision of 24 or lower will in fact be created as a float(24)
. And a synonym for float(24)
is real
. The system doesn't remember whether it was originally specified as float(1)
, float(24)
or real
.
为什么当 float 指定了精度时,默认情况下它会转换为 real?
Why is it getting converted to real by default whenever float has a precision specified?
它没有.如上所述,如果您创建一个类型为 float(25)
(或任何更高精度)的列,您会发现它以普通的 float
形式返回,而不是real
,因为它是作为 float(53)
创建的,当没有提供时,53 是默认精度.
It doesn't. As per the above, if you create a column with type float(25)
(or any higher precision), you'll find it gets returned as plain float
, rather than real
, because it was created as a float(53)
and 53 is the default precision when none is supplied.
这篇关于在创建“精度浮动"类型的表列时列被创建为“真实的"键入 SQL 服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!