在数据库 Sql 服务器中存储为 Real 的浮点数
Float stored as Real in database Sql Server
为什么 Float
在 sys.columns
中存储为 Real
或在 precision <= 24
中存储为 Information_schema.columns
。
CREATE TABLE dummy
(
a FLOAT(24),
b FLOAT(25)
)
检查数据类型
SELECT TABLE_NAME,
COLUMN_NAME,
DATA_TYPE,
NUMERIC_PRECISION
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = 'dummy'
结果:
+------------+-------------+-----------+-------------------+
| TABLE_NAME | COLUMN_NAME | DATA_TYPE | NUMERIC_PRECISION |
+------------+-------------+-----------+-------------------+
| dummy | a | real | 24 |
| dummy | b | float | 53 |
+------------+-------------+-----------+-------------------+
那么当precision
小于或等于24
时,为什么float
存储为real
。这在某处记录了吗?
The ISO synonym for real is float(24).
Please refer for more info:
https://msdn.microsoft.com/en-us/library/ms173773.aspx
来自讨论 T-SQL 中 float
和 real
之间区别的 MSDN article:
The ISO synonym for real is float(24).
float [ (n) ]
Where n is the number of bits that are used to store the mantissa of the float number in scientific notation and, therefore, dictates the precision and storage size. If n is specified, it must be a value between 1 and 53. The default value of n is 53.
n value | Precision | Storage size
1-24 | 7 digits | 4 bytes
24-53 | 15 digits | 8 bytes
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.
至于为什么SQL服务器将其标记为real
,我认为它只是一个同义词。但是,在引擎盖下它仍然是 float(24)
.
为什么 Float
在 sys.columns
中存储为 Real
或在 precision <= 24
中存储为 Information_schema.columns
。
CREATE TABLE dummy
(
a FLOAT(24),
b FLOAT(25)
)
检查数据类型
SELECT TABLE_NAME,
COLUMN_NAME,
DATA_TYPE,
NUMERIC_PRECISION
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = 'dummy'
结果:
+------------+-------------+-----------+-------------------+
| TABLE_NAME | COLUMN_NAME | DATA_TYPE | NUMERIC_PRECISION |
+------------+-------------+-----------+-------------------+
| dummy | a | real | 24 |
| dummy | b | float | 53 |
+------------+-------------+-----------+-------------------+
那么当precision
小于或等于24
时,为什么float
存储为real
。这在某处记录了吗?
The ISO synonym for real is float(24).
Please refer for more info:
https://msdn.microsoft.com/en-us/library/ms173773.aspx
来自讨论 T-SQL 中 float
和 real
之间区别的 MSDN article:
The ISO synonym for real is float(24).
float [ (n) ]
Where n is the number of bits that are used to store the mantissa of the float number in scientific notation and, therefore, dictates the precision and storage size. If n is specified, it must be a value between 1 and 53. The default value of n is 53.
n value | Precision | Storage size
1-24 | 7 digits | 4 bytes
24-53 | 15 digits | 8 bytes
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.
至于为什么SQL服务器将其标记为real
,我认为它只是一个同义词。但是,在引擎盖下它仍然是 float(24)
.