sql - Float 在数据库 Sql Server 中存储为 Real

标签 sql sql-server tsql precision sqldatatypes

为什么是Float存储为 Realsys.columnsInformation_schema.columns什么时候precision <= 24 .

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 |
+------------+-------------+-----------+-------------------+

那为什么是float存储为 realprecision小于或等于 24 .这在某处记录了吗?

最佳答案

来自MSDN article其中讨论了 T-SQL 中 floatreal 之间的区别:

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 Server把它标为real,我觉得只是一个同义词而已。然而,在引擎盖下它仍然是一个 float(24)

关于sql - Float 在数据库 Sql Server 中存储为 Real,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41628665/

相关文章:

SQL Server 2005 卡住(因为应用程序),需要日志记录

sql-server - SQL Server 中的 "with (nolock)"是什么?

sql - 按列分组并根据条件构建单个结果行

sql - 在 View 中执行存储过程?

tsql - SQL 中的排序

c# - 出版物(网络): Object reference not set to an instance of an object when trying to publish a web site

mysql - 如何修复插入后触发计数时mysql代码中的错误

sql - 加载数据内文件 (*.csv) - 忽略空单元格

sql - MS SQL 临时表

sql-server-2005 - 循环遍历服务器上的数据库,并更新数据