2

Why is Float stored as Real in sys.columns or Information_schema.columns when precision <= 24.

CREATE TABLE dummy
  (
     a FLOAT(24),
     b FLOAT(25)
  ) 

checking the data type

SELECT TABLE_NAME,
       COLUMN_NAME,
       DATA_TYPE,
       NUMERIC_PRECISION
FROM   INFORMATION_SCHEMA.COLUMNS
WHERE  TABLE_NAME = 'dummy' 

Result:

+------------+-------------+-----------+-------------------+
| TABLE_NAME | COLUMN_NAME | DATA_TYPE | NUMERIC_PRECISION |
+------------+-------------+-----------+-------------------+
| dummy      | a           | real      |                24 |
| dummy      | b           | float     |                53 |
+------------+-------------+-----------+-------------------+

So why is float stored as real when the precision is less than or equal to 24. Is this documented somewhere ?

Pரதீப்
  • 91,748
  • 19
  • 131
  • 172

2 Answers2

3

The ISO synonym for real is float(24).
Please refer for more info:
https://msdn.microsoft.com/en-us/library/ms173773.aspx
User
  • 804
  • 8
  • 22
3

From an MSDN article which discusses the difference between float and real in T-SQL:

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.

As to why SQL Server labels it as real, I think it is just a synonym. However, underneath the hood it is still a float(24).

Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360
  • @Prdp I don't think it's storing it as `real`, but rather `float(24)`. It is _labeling_ it as `real`. – Tim Biegeleisen Jan 13 '17 at 06:42
  • Am comparing datatypes between two similar databases. This `Real` made me to go crazy because we don't create datatypes with `Real` :D. Later I realised that `Float` is what stored as `Real` – Pரதீப் Jan 13 '17 at 06:47